let treeData =[
name: "张三",
level: "爷爷",
children: [
name: "张5",
level: "爸爸",
children: [
name: "张6",
level: "宝宝",
children: []
]
]
]
const newTreeData = treeDone(treeData);
function treeDone(data){
data.forEach(item => {
if (item.children && item.children.length > 0) {
item = treeDone(item.children);
} else {
delete item.children;
}
return item
});
return data
}