immutable中Map中嵌套的List怎么更新?

发布于 2022-09-05 20:42:42 字数 190 浏览 40 评论 0

有没有对immutable比较了解的朋友?

immutable中Map中嵌套的List怎么更新?

就是Map中嵌套了一个List,List中的每一个元素又是Map,现在知道List中的一个元素的id,然后我想根据这个id来更新这个元素,应该要怎么做?

单独的一个Map或者List我是知道怎么更新的,但是如果是嵌套的呢?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

中二柚 2022-09-12 20:42:44
const nested4 = nested3.updateIn([ 'a', 'b', 'c' ], list => list.push(6))
// Map { a: Map { b: Map { c: List [ 3, 4, 5, 6 ], d: 7 } } }
握住你手 2022-09-12 20:42:44
return state.updateIn(['adminList', index, 'phone'], () =>  phone)
            .updateIn(['adminList', index, 'email'], () =>  email)

update单独更新一个,如果多层嵌套,采用updateI([A,B,C],() => value),其中ABC表示在A对象下面的B对象下面的C对象,()=>value表示更新成什么数据

花开浅夏 2022-09-12 20:42:44

let listData = List([

{id: 1, name: "first", count: 2},
{id: 2, name: "second", count: 1},
{id: 3, name: "third", count: 2},
{id: 4, name: "fourth", count: 1}

])
想要更新 name=first 中的Count中的值

let list = state.getIn(['listData']);
list = list.update(list.findIndex(function(item){

return item.get('name') ==='third'; 
}),function(item){
    return item.set('count',400) 
} 

);

可是会报错 "item.get is not a function"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文