【发布时间】:2019-11-25 22:34:20
【问题描述】:
我正在尝试过滤嵌套级别为 3 的数组。我必须在最后一级过滤此数组。
array = [{
children: [{
children: [{
children: [],
id: 2694,
name: "Some Random data"
}, {
children: [],
id: 2695,
name: "Another Random Data"
}],
id: 2574,
name: "Test data",
}],
id: 2530,
name: "Main Test data"
}, {
children: [{
children: [{
children: [],
id: 2696,
name: "Secondary test Data"
}, {
children: [],
id: -1,
name: "Random Text"
}],
id: 2575,
name: "Another random Text"
}],
id: 2531,
name: "New Data"
}]
这个功能我试过了
function(random){
let array3=[];
this.array.forEach(cap=>{
let tempparent={...cap};
let child1= tempparent.children.forEach(ch=>{
let tempfeat={...ch};
let tempchildren = tempfeat.children.filter(fe=>{
if(fe.id!=random.id){
return fe
}
});
// console.log(tempchildren)
tempfeat.children = tempchildren;
// console.log(tempfeat.children)
});
console.log(child1)
tempparent.children= child1;
console.log(tempparent.children)
nodes3.push(tempparent)
})
this.array= array3
console.log(this.array);
}
我想使用 id 值在第三级过滤它。当 id 与匹配的对象匹配时,必须删除。
【问题讨论】:
-
我想使用 id 值在第三级过滤它。当 id 匹配匹配的对象时必须删除
-
请将想要的结果与错误一起添加到问题中,您会得到。
-
或者我们可以通过 id 过滤完整的嵌套数组吗?如果 id 匹配匹配的对象必须删除
-
我想要结果,因为只要 id 匹配,必须从给定数组中删除匹配的 id 对象
标签: javascript typescript