setTreeData(source) {
let cloneData = JSON.parse(JSON.stringify(source))
return cloneData.filter(father => {
// 循环所有项,并添加children属性
father.id = father.ID;
father.label = father.ClassificationName;
let branchArr = cloneData.filter(child => {
child.id = child.ID;
child.label = child.ClassificationName;
return father.ID == child.ParentID
}); // 返回每一项的子级数组
branchArr.length > 0 ? father.children = branchArr : '' //给父级添加一个children属性
return father.ParentID == null; //返回第一层,
});
},
网友评论