我想更改类似这样的对象的属性,这是一个简化的对象,具有原始的一些属性:
state = {
pivotComuns: [
{
id: 1,
enabled : true
},
{
id: 2,
enabled : true
}
],
otherProperties : "otherProperties"
}
我正在像这样更改启用的状态:
state = {
...state,
pivotColumns: {
...state.pivotColumns,
[2]: {
...state.pivotColumns[2], enabled: !state.pivotColumns[2].enabled
}
}
}
它可以工作,但不是像我一样返回一个数组,而是 pivotComuns 属性,它返回一个对象,“注意我将 [] 更改为 {}”:
state = {
pivotComuns: {
{
id: 1
enabled : true
},
{
id: 2,
enabled : true
}
},
otherProperties : "otherProperties"
}
我做错了什么,我需要将该属性保留为数组。