我在Map
对象中有一个不可变的列表对象,如下所示:
let initialState = Immutable.fromJS({});
state = initialState;
state = state.set("myList", Immutable.List());
如何将值附加到" myList",从而更新state
?
答案 0 :(得分:16)
您可以使用update()方法。
const initialState = Immutable.fromJS({});
const state = initialState.set('myList', Immutable.List());
const updatedState = state.update('myList', myList => myList.push('some value'));
答案 1 :(得分:2)
emails = List(new Array<string>());
defaultValues = ['gold@gmail.com', 'saphire@gmail.com'];
this.emails = this.emails.push(...this.defaultValues);
这是打字稿。