Javascript 如何更新不可变列表中的特定值?

Javascript 如何更新不可变列表中的特定值?,javascript,redux,immutable.js,Javascript,Redux,Immutable.js,我正在做一个架构,尝试使用 这是我的秘密。。。鉴于这种情况: var state = Immutable.fromJS([ {"id":0, "url":"http://someUrl", "thumb_url":"http://someUrl", "other_url":"http://someUrl"}, {"id":3, "url":"http://someUrl", "thumb_url":"http://someUrl", "alternative_url":"http://s

我正在做一个架构,尝试使用

这是我的秘密。。。鉴于这种情况:

var state = Immutable.fromJS([
  {"id":0, "url":"http://someUrl", "thumb_url":"http://someUrl", "other_url":"http://someUrl"},
  {"id":3, "url":"http://someUrl", "thumb_url":"http://someUrl", "alternative_url":"http://someUrl"},
  {"id":1, "url":"http://someUrl", "thumb_url":"http://someUrl", "alternative_url":"http://someUrl"},
  {"id":5, "url":"http://someUrl", "thumb_url":"http://someUrl", "yet_another_url":"http://someUrl"}
])
…我想更新
url
。我尝试过更新第三个
索引的
url
,如下所示:

var index = 2;
var new_item = { id: 1, url: 'my_new_url' };

var state = state.setIn([index], new_item);
我的问题是,我只需要更新
url
(或其他属性,如
thumb\u url
),保持所有未更改的属性不变。我有一个
新项目
,我想将其中的相关更新部分插入到给定索引中。如何在不递归旧项的每个单独属性和不丢失现有属性的情况下做到这一点

当我说“更新”时,我的意思是创建一个新的
状态
,将旧的值更改为新的值,这与Immutable.js很常见

谢谢

将设置一个新值,该值将覆盖以前的值,您可能需要将新属性合并到原始值

var state=Immutable.fromJS([
{“id”:0,“url”:http://someUrl,“拇指url”:http://someUrl,“其他url”:http://someUrl"},
{“id”:3,“url”:http://someUrl,“拇指url”:http://someUrl,“备选url”:http://someUrl"},
{“id”:1,“url”:http://someUrl,“拇指url”:http://someUrl,“备选url”:http://someUrl"},
{“id”:5,“url”:http://someUrl,“拇指url”:http://someUrl,“还有一个url”:http://someUrl"}
])
var指数=2;
var new_item={id:1,url:'my_new_url'};
var state=state.mergeIn([index],新的_项);
console.log(state.toJS())
将设置一个新值,该值将覆盖以前的值,您可能需要将新属性合并到原始值

var state=Immutable.fromJS([
{“id”:0,“url”:http://someUrl,“拇指url”:http://someUrl,“其他url”:http://someUrl"},
{“id”:3,“url”:http://someUrl,“拇指url”:http://someUrl,“备选url”:http://someUrl"},
{“id”:1,“url”:http://someUrl,“拇指url”:http://someUrl,“备选url”:http://someUrl"},
{“id”:5,“url”:http://someUrl,“拇指url”:http://someUrl,“还有一个url”:http://someUrl"}
])
var指数=2;
var new_item={id:1,url:'my_new_url'};
var state=state.mergeIn([index],新的_项);
console.log(state.toJS())