简体   繁体   English

如何在ImmutableJS中更新深层列表?

[英]How to update deep list in ImmutableJS?

Can anyone tell me what how to update 'value' by id in this structue in ImmutableJS? 谁能告诉我在ImmutableJS中如何通过id更新“值”?

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 . 如果可以更改结构而不是List ,则可以使用OrderedMap

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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