【发布时间】:2018-10-31 03:41:11
【问题描述】:
我正在尝试更新我的 redux crud 表单。我在 immutatbility helper 的帮助下使用。 我的减速机是:
case UPDATE_TODO:
console.log("reducer todo",action.toDo,state)
return update(state, { $set: [action.toDo] })
但不是替换特定对象,而是将整个数组替换为一个。我在哪里做错了? 我的状态是这样的:
[
{_id: "5b3d2696e099830f249dddfd", title: "hello", description: "hello", reminder: "2018-07-05T01:27", date: "1530734230965", …}
{_id: "5b3d2696e099830f249dddxe", title: "hello", description: "hello", reminder: "2018-07-05T01:27", date: "1530734230965", …}
]
更新后应该是这样的:
[
{_id: "5b3d2696e099830f249dddfd", title: "hello", description: "hello", reminder: "2018-07-05T01:27", date: "1530734230965", …}
{_id: "5b3d2696e099830f249dddxe", title: "hello1", description: "hello", reminder: "2018-07-05T01:27", date: "1530734230965", …}
]
但它给出的结果是:
[
{_id: "5b3d2696e099830f249dddxe", title: "hello1", description: "hello", reminder: "2018-07-05T01:27", date: "1530734230965", …}
]
【问题讨论】:
标签: javascript reactjs redux react-redux