const treeData = [{
title: "1",
key: "1",
children: [{
title: "1-1",
key: "1-1",
children:[{
title:"1-1-1",
key:"1-1-1",
},{
title:"1-1-2",
key:"1-1-2",
}]
}, {
title: "1-2",
key: "1-2",
},{
title: "1-3",
key: "1-3",
},{
title: "1-4",
key: "1-4",
}],
}];
want to filter the tree through the incoming key,. If the parent is dropped by Filter, all the children below the parent are also Filter.
I didn"t achieve the effect of Filter through recursive map, or recursive filter. The code is as follows:
deleteTreeData = (data,selectedKey) => {
const newTreeData = data.filter((item) => {
if(item.children){
this.deleteTreeData(item.children,selectedKey);
}
return item.key !== selectedKey;
});
this.setState({
treeData : newTreeData,
},function(){
console.log("=====newTreeData:"+JSON.stringify(newTreeData));
});
}
if you write this, you can only delete the top-level menu. What is the correct idea? thank you.