、これは元のいくつかのプロパティを持つ単純化されたオブジェクトです:変更プロパティ私はこれに似たオブジェクトのプロパティを変更するオブジェクトの代わりに、配列
state = {
pivotComuns: [
{
id: 1,
enabled : true
},
{
id: 2,
enabled : true
}
],
otherProperties : "otherProperties"
}
私は」このような有効の状態を変更するM:
state = {
...state,
pivotColumns: {
...state.pivotColumns,
[2]: {
...state.pivotColumns[2], enabled: !state.pivotColumns[2].enabled
}
}
}
それが動作するが、代わりに復帰Iのようなアレイは、「私は} {ための[]変更通知」がオブジェクトを返すpivotComuns性がある:
state = {
pivotComuns: {
{
id: 1
enabled : true
},
{
id: 2,
enabled : true
}
},
otherProperties : "otherProperties"
}
私が間違っていることは、そのプロパティを配列にしておく必要があることです。
あなたの元のコードが欠落している '' {... – Aaron
@Aaronだけではなく、 '{'、 '、'また、オブジェクトデータ –
右に私は、コードを更新しました行方不明。 –