【发布时间】:2018-05-10 19:22:26
【问题描述】:
我有一个 ul 组件,我想在完成 ajax 请求时重新渲染所有子 li。 ajax 请求完成后,我将 response.data 传递给状态。我可以 console.log 状态并查看数据已更改,但是孩子永远不会重新渲染。
export class Tiles extends React.Component {
constructor() {
super();
this.state = {
items: []
};
this.itemList = this.state.items.map((items)=>{
return <ModalTest key={item.id} items={items}/>
});
}
//This is the local fake data standing in for the real DB
componentDidMount() {
axios.get('/tiles/')
.then((res)=>{
console.log(res.data);
this.setState({items:res.data});
});
}
render() {
return (
<ul className="tiles-ul">
{this.itemList}
</ul>
);
}
}
【问题讨论】:
标签: javascript reactjs rendering axios