【发布时间】:2018-03-27 11:12:50
【问题描述】:
我有以下对象。当用户单击按钮时,此对象会被分配一个新值。
state = {
title: '',
id: '',
imageId: '',
boarding: {
id: '',
test: '',
work: {
title: '',
id: ''
}
}
}
我更新的对象如下所示:
state = {
title: 'My img',
id: '1234',
imageId: '5678-232e',
boarding: {
id: '0980-erf2',
title: 'hey there',
work: {
title: 'my work title',
id: '456-rt3'
}
}
}
现在我想更新状态内的工作对象并保持一切不变。当对象没有嵌套但混淆嵌套时,我使用了Object.assign()。
Object.assign({}, state, { work: action.work });
我的 action.work 拥有整个工作对象,但现在我想将其设置为登机,但这会替换登机中的所有内容,这不是我想要的。
【问题讨论】:
标签: javascript reactjs ecmascript-6 redux react-redux