我有这个immutableJs地图:
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 to visible:false。我用filter,seq等尝试了很多不同的方法。但没有运气。
关于如何使用immutableJs做任何想法?
答案 0 :(得分:0)
晚些时候参加聚会,但是怎么样(假设您的数据在名为data
的变量中):
data.setIn(["event", "days"],
data.getIn(["event", "days"]).map(day =>
day.set("sessions", day.get("sessions").map(session =>
session.setIn(['details', 'visible'], false)))
)
)
答案 1 :(得分:-1)
在ES6中,可能很容易翻译成immutableJS ....
const notVisibleEvents = {
...events,
days: events.days.map(d => {
return {
...d,
sessions: d.sessions.map(s => {
return {
...s,
details: {
...s.details,
visible: false
}
};
})
};
})
};