标签:each data uil dep 递归 turn push path array
///将扁平化之后的数组还原成树
buildTree = (list) => {
let dataArray = [];
list.forEach(item=>{
if(item._parent_path ===‘‘){
dataArray.push(item);
}
});
return this.data2treeDG(list, dataArray);
};
data2treeDG(datas, dataArray){
dataArray.forEach(item=>{
let childrenArray = [];
let CATL_CODEP = item._path;
datas.forEach(items=>{
let data = items;
let CATL_PARENT = data._parent_path;
if(CATL_CODEP===CATL_PARENT){
childrenArray.push(items);
}
});
item.children = childrenArray;
if(childrenArray.length > 0) {//有儿子节点则递归
this.data2treeDG(datas, childrenArray);
}
});
return dataArray;
}
};
标签:each data uil dep 递归 turn push path array
原文地址:https://www.cnblogs.com/boonook/p/10172167.html