I use the following to loop out data for nearly 23
seconds. Is there a better way to optimize < del > Thank you < / del >
export async function getOrgTree(treeArray){
let r = [];
let tmpMap ={};
for(let i = 0, len = treeArray.length; i < len; iPP){
tmpMap[treeArray[i]["code"]]= treeArray[i];
}
for(let i = 0, len = treeArray.length; i < len; iPP){
let key = tmpMap[treeArray[i]["parentCode"]];
if (key) {
if (!key["children"]) {
key["children"] = [];
key["children"].push(treeArray[i]);
} else {
if (key["children"].findIndex(v => v.code === treeArray[i].code) === -1) {
key["children"].push(treeArray[i]);
}
}
if(!treeArray[i]["parentCode"]||treeArray[i]["parentCode"]==="0"||treeArray[i]["parentCode"]==="root"){
r.push(treeArray[i]);
}
} else if (!treeArray[i]["parentCode"]||treeArray[i]["parentCode"]==="0"||treeArray[i]["parentCode"]==="root"){
r.push(treeArray[i]);
}
}
return r;
}