2017-06-12 64 views
0

我是Framework ReactJS的新手,我试图在一个页面上创建两个不同的页面。每个获得不同数组的数据库。 你能帮我理解这个错误吗?无法读取undefined的属性'slice'

Error_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); 
+0

看来'this.props.array_1'(可能'this.props.array_2')没有被定义。你是否将它们作为道具发送给你的组件?如果您的“获取”是http GET,那么您可能需要等待响应才能呈现组件。那有意义吗?在获得实际数据之前,您可能正在渲染它。 – byumark

回答

0

perfaps这个链接将帮助它具有相同的问题: link

我觉得是传递一个空对象bootstrapTable的数据,因为它仅接受阵列的问题。 你应该检查你是否

相关问题