【发布时间】:2017-03-15 14:11:56
【问题描述】:
我是 ReactJS 的新手,在我的一个组件渲染块中,地图被正确执行,后来它显示错误。
class CustomerList extends Component {
constructor(props,context) {
super(props, context);
this.loadCustomersFromServer()
}
loadCustomersFromServer() {
$.ajax({
url: '/customers',
dataType: 'json',
success: (data) => {
this.setState({results: data});
},
error: (xhr, status, err) => {
console.error(this.props.url, status, err.toString());
}
});
}
componentDidUpdate(){
console.log("componentDidUpdate")
}
componentWillUpdate(){
console.log("componentWillUpdate")
}
render() {
return (
<div className="col-lg-12">
<h1>Registered Clients</h1>
<div className="table-responsive">
<table className="table table-bordered table-striped">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Address</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{
this.state.results.customers.map((customer, index) => {
return <Customer key={index+1} index={index+1} customer={customer}/>
})
}
</tbody>
</table>
</div>
</div>
)
}
}
export default CustomerList
在我的浏览器中,所有表格都完美呈现,但在我的控制台中显示错误提示
无法在 CustomerList.render (CustomerList.js:44) 处读取 null 的属性“结果”
在这一行
this.state.results.customers.map
我是否错过了一些使我的地图函数在空状态下触发两次的东西??
【问题讨论】:
标签: reactjs