需求:对后台返回的数据做处理。返回的数组中,第一个对象的value:[11,21,42],但是children中id不包含42,应该用数组中移除,最终value:[11,21]。同理,第二个数组中 value:[42]后台返回格式:[{"children": [ { "id": 11, "typeName": "水果类" }, { "id": 21, "typeName": "水果类" }],"title": "水果类","value": [11,21,42]},{"children": [ { "id": 42, "typeName": "展示类" }],"title": "展示类","value": [11,21,42]}
2 回答
慕村225694
TA贡献1880条经验 获得超4个赞
let data = [{
"children": [{
"id": 11,
"typeName": "水果类"
}, {
"id": 21,
"typeName": "水果类"
}],
"title": "水果类",
"value": [11]
}, {
"children": [{
"id": 42,
"typeName": "展示类"
}],
"title": "展示类",
"value": [11,21,42]
}]
data.forEach(item => {
let keys = item.children.map(a => a.id)
item.value = item.value.filter(i => keys.includes(i))
})
添加回答
举报
0/150
提交
取消