我有以下函数来获取 currentStatus 和 id 并根据上述参数更改值。我有以下状态。
this.state.column : [
[
arr1 : { id: 1, currentStatus: ''to-do'},
{ id: 4, currentStatus: ''completed'},
],
[
arr2 : { id: 10, currentStatus: ''in-progress'},
{ id: 14, currentStatus: ''completed'},
],
]
我将新的 currentStatus 和特定的 id 作为参数提供给以下函数,并且需要用新的 currentStatus 替换现有的 currentStatus。特定对象可以通过 id 找到(对于整个数组来说是唯一的)。我正在尝试以下代码,最后得到错误Cannot read property 'nn' of undefined
import update from 'immutability-helper';
getCurrentStatus = (currentStatus, id) => {
Object.keys(this.state.columns).forEach(ee => {
if (this.state.columns[ee].find(x => x.id === id)){
var nn = this.state.columns[ee].findIndex(x => x.id === id)
this.setState({
columns : update(this.state.columns, {ee:{nn:{$set : currentStatus}}})
}, () =>
console.log(this.state.columns)
)
}
})
}