1 回答
TA贡献1876条经验 获得超6个赞
我认为正确的方法是这样的。(#edit:它适用于片段)
var id = 1,
frameId=2;
var sizes = [
{
id: 1,
name: 'Mrec',
frames: [
{
frameId: 1,
template: {},
img: [],
},
{
frameId: 2,
template: {},
img: [],
},
],
active: false
},
{
id: 2,
name: 'Leaderboard',
frames: [
{
frameId: 1,
template: {},
img: [],
},
{
frameId: 2,
template: {},
img: [],
},
],
active: false
}
]
sizes.map(size => {
let frames;
if (size.id === id) {
frames = size.frames.map(frame => {
if (frame.frameId === frameId) {
frame.template = { test: '101' }
}
return frame;
})
} else {
frames = size.frames;
}
return {...size,frames}
})
document.write(JSON.stringify(sizes))
添加回答
举报