【发布时间】:2019-08-12 22:30:04
【问题描述】:
我正在尝试向任务对象添加注释,但到目前为止我已经将它添加到所有任务中。当我尝试不同的方式时,它不会编译。 Object.assign 不喜欢在 .push() 之后出现
当它添加到所有任务时:
let taskReducer = function(tasks = [], action) {
switch (action.type) {
case 'ADD_NOTE':
return tasks.map((task) => {
const { notes } = task;
const { text } = action;
notes.push({
text,
id: notes.length,
})
return task.id === action.id ?
Object.assign({}, { task, notes }) : task
})
当它不编译时:
let taskReducer = function(tasks = [], action) {
switch (action.type) {
case 'ADD_NOTE':
return tasks.map((task) => {
return task.id === action.id ?
const { notes } = task;
const { text } = action;
notes.push({
text,
id: notes.length,
})
Object.assign({}, { task, notes }) : task
})
【问题讨论】: