Append value to List

陌路散爱 提交于 2019-12-05 20:22:52

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!