data 数据格式:
所有对象,都有id:' ', 和 children:[ ],
对象中的,children 可能会嵌套 一个或多个对象,也可能是空[] ,而且嵌套很多层
现在我要 找出 id 为 ** 的对象,把它删除
如: {id: 1,children:[ {id: 2,children:[ {id: 3,children:[ {id: 4,children:[] }] }] }, {id: 5,children:[] }, {id: 6,children:[] }] }
export function deleteEl(data,id){
// if(typeof data === 'undefined'){return data}
// if(typeof data.children === 'undefined'){return data}
if (data.children.length>=1){
for(let i=0;i<data.children.length;i++){
if(data.children[i].id=== id){
data.children.splice(i,1)
console.log('删除',id)
return data
}
if(data.children[i].children.length >= 1) {
for(let j=0; j < data.children[i].children.length; j++){
if(data.children[i].children[j].id === id){
data.children[i].children.splice(j,1)
console.log('删除',id)
return data
}
if(data.children[i].children[j].children.length>=1){
for(let x=0; x< data.children[i].children[j].children.length; x++){
if(data.children[i].children[j].children[x].id === id ){
data.children[i].children[j].children.splice(x,1)
console.log('删除',id)
return data
}
if(data.children[i].children[j].children[x].children.length>=1){
for(let y=0; y<data.children[i].children[j].children[x].children.length;y++){
if(data.children[i].children[j].children[x].children[y].id=== id){
data.children[i].children[j].children[x].children.splice(y,1)
console.log('删除',id)
return data
}
if(data.children[i].children[j].children[x].children[y].children.length>=1){
for(let z=0;z<data.children[i].children[j].children[x].children[y].children.length;z++){
if(data.children[i].children[j].children[x].children[y].children[z].id === id){
data.children[i].children[j].children[x].children[y].children.splice(z,1)
console.log('删除',id)
return data
}
}
}
}
}
}
}
}
}
}
}
}