我想从 Prop 渲染项目,我可以用初始状态来做,但不能用服务器的响应。我的渲染函数:
const { data } = this.props;
return (
<div >
{data.map((item, index) =>
<div key={index} className="row">
<span data = { data } className="number col-4 col-md-8">{item._id}</span>
<span data = { data } className="date col-4 col-md-2">{item.date}</span>
<span data = { data } className="tag col-4 col-md-2">{item.tag}</span>
<div className="col-md-12 ">
{item.text}
</div>
</div>
)}
</div>
)
}
我犯了这个错误:
TypeError: e.map is not a function
response : Object {data: Array(12), status: 200, statusText: "OK", headers: Object, config: Object…}
最佳答案
不得不改变父组件改变这个:
this.setState({
data: response
})
到
this.setState({
data: response.data
})
我试图从子组件获取数据,但没有成功(可能是因为 map 函数)
关于javascript - React 中的 Map 函数(err : TypeError: e. map is not a function),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45787301/