简体   繁体   中英

How to update deep list in ImmutableJS?

Can anyone tell me what how to update 'value' by id in this structue in ImmutableJS?

map = {
  list: [
    {
      id: 1,
      value: 'update'  
    }
  ]
}

You can use the code below. However, it is not the best solution, because that will search all items in the list. If you can change your structure instead of List you can use OrderedMap .

var newData = map.set("list", map.get("list").map(data => data.get("id") === 1 ? data.set("value", "updatedValue") : data));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM