问题
I have a immutable list object, within a Map
object, as follows:
let initialState = Immutable.fromJS({});
state = initialState;
state = state.set("myList", Immutable.List());
How do I append a value to "myList", thereby updating state
?
回答1:
You can use update() method.
const initialState = Immutable.fromJS({});
const state = initialState.set('myList', Immutable.List());
const updatedState = state.update('myList', myList => myList.push('some value'));
回答2:
emails = List(new Array<string>());
defaultValues = ['gold@gmail.com', 'saphire@gmail.com'];
this.emails = this.emails.push(...this.defaultValues);
This is for typescript .
来源:https://stackoverflow.com/questions/40589928/append-value-to-list