1
必须避免state
对象中的任何突变。你能否建议,如何通过rowId使用Immutable.Map()
更改行文本?如何使用ImmutableJS Map设置嵌套数组中项目的属性?
setIn
在这种情况下,函数似乎不适用于Map吗?
var state = {
pages: [
{
tiles: [
{
rows: [
{rowId: 'row1', text: 'text1'},
{rowId: 'row2', text: 'text2'},
{rowId: 'row3', text: 'text3'}
//...
]
},
{
//...
}
//...
]
}
//...
]
};
function onRowUpdateAction(state, rowId, rowText) {
var map = Immutable.Map(state);
//TODO: Update row text by row id ?
return map.toObject();
}
var newState = onRowUpdateAction(state, 'row2', 'updatedText');
在此先感谢!