1 回答

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超6個(gè)贊
我認(rèn)為正確的方法是這樣的。(#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))
添加回答
舉報(bào)