0
我是Framework ReactJS的新手,我試圖在一個頁面上創建兩個不同的頁面。每個獲得不同數組的數據庫。 你能幫我理解這個錯誤嗎?無法讀取undefined的屬性'slice'
class Example extends React.Component{
constructor (props) {
super(props);
this.props.dispatch (get1({email:this.props.email}),get2({email:this.props.email}));
this.options = {
onPageChange: this.onPageChange.bind(this),
onSizePerPageList: this.sizePerPageListChange.bind(this)
};
}
sizePerPageListChange(sizePerPage) {
alert(`sizePerPage: ${sizePerPage}`);
}
onPageChange(page, sizePerPage) {
alert(`page: ${page}, sizePerPage: ${sizePerPage}`);
}
componentDidMount() {
setTimeout(() => {
this.refs.table2.forceUpdate();
this.refs.table3.forceUpdate();
}, 500);
}
render() {
return (
<table width={1000} height={500}>
<tr>
<td>
<BootstrapTable ref="table2" data={ this.props.array_1 }
options={ this.options } multiColumnSort={ 2 } striped hover>
<td dataField='att_1' isKey={true} width="55px">Col_1</td>
<td dataField='att_2' width="140px">Col_1</td>
<td dataField='att_3' width="140px">Col_2</td>
<td dataField='att_4' width="30px">Col_3</td>
</BootstrapTable>
</td>
<td width={50}> </td>
<td>
<BootstrapTable ref="table3" data={ this.props.array_2 }
options={ this.options } multiColumnSort={ 2 } striped hover>
<td dataField='att_5' isKey={true} width="55px">Col_4</td>
<td dataField='att_6' width="140px">Col_5</td>
<td dataField='att_7' width="30px">Col_6</td>
</BootstrapTable>
</td>
</tr>
</table>
);
}
};
function mapStateToProps(state){
return{
array_1: state.proj.array_1,
array_2: state.hist.array_2,
email: state.email
};
}
export default connect(mapStateToProps,{get1,get2})(Example);
看來'this.props.array_1'(可能'this.props.array_2')沒有被定義。你是否將它們作爲道具發送給你的組件?如果您的「獲取」是http GET,那麼您可能需要等待響應才能呈現組件。那有意義嗎?在獲得實際數據之前,您可能正在渲染它。 – byumark