您需要转换待办事项数组以更新适当的项目。Array.map是执行此操作的最简单方法:
case "COMPLETE_TASK": return { ...state, todos: state.todos.map(todo => todo.id === action.id ? // transform the one with a matching id { ...todo, completed: action.completed } : // otherwise return original todo todo ) };有一些库可以帮助您进行这种深度状态更新。您可以在此处找到此类库的列表:https :
//github.com/markerikson/redux-ecosystem-links/blob/master/immutable-
data.md#immutable-update-utilities
就我个人而言,我使用ImmutableJS(https://facebook.github.io/immutable-
js/)来解决其
updateIn和
setIn方法的问题(对于具有大量键和数组的大型对象,它们和普通对象和数组相比效率更高,但对于小孩子则较慢)。



