gpt4 book ai didi

javascript - Immutablejs - 更新嵌套映射和列表中的值

转载 作者:行者123 更新时间:2023-11-28 10:51:04 24 4
gpt4 key购买 nike

我有这个 immutableJs map :

event: {
days: [
{
date: 1,
sessions: [
{
id: 1,
name: 2,
startTime: 1,
endTime: 1,
description: 1,
detailsLink: 1,
details: {visible: true}
},
{
id: 2,
name: 2,
startTime: 2,
endTime: 2,
description: 2,
detailsLink: 2,
details: {visible: false}
},
{
id: 3,
name: 3,
startTime: 3,
endTime: 3,
description: 3,
detailsLink: 3,
details: {visible: true}
}
]
},
{
date: 2,
sessions: [
{
id: 1,
name: 2,
startTime: 1,
endTime: 1,
description: 1,
detailsLink: 1,
details: {visible: false}
},
{
id: 2,
name: 2,
startTime: 2,
endTime: 2,
description: 2,
detailsLink: 2,
details: {visible: false}
},
{
id: 3,
name: 3,
startTime: 3,
endTime: 3,
description: 3,
detailsLink: 3,
details: {visible: true}
}
]
}
]
}

我想将可见的:true 更新为visible:false。我尝试了很多不同的方法,包括过滤器、序列等,但没有运气。

关于如何使用 immutableJs 做到这一点有什么想法吗?

最佳答案

聚会迟到了,但是这样怎么样(假设您的数据位于名为 data 的变量中):

data.setIn(["event", "days"],
data.getIn(["event", "days"]).map(day =>
day.set("sessions", day.get("sessions").map(session =>
session.setIn(['details', 'visible'], false)))
)
)

关于javascript - Immutablejs - 更新嵌套映射和列表中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33353098/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com