【发布时间】:2018-11-13 10:08:30
【问题描述】:
我有一个状态为的值数组
constructor {
super(props);
this.state = {
staff: {
pos1: { name:'Ajith'}
pos2: { name:'Ben'}
}
}
}
componentDidMount() {
this.state.staff.map((item,index) => {
console.log(item+" * "+index)
}
}
我收到错误 this.state.staff.map is not a function,因为索引与 0, 1 etc 不同。我该如何解决这个问题?
【问题讨论】:
-
因为 this.state.staff 不是数组!!。这是一个对象
-
loop on object的可能重复
标签: reactjs