正常数组转换为树状结构
1、这里子元素的标识是menuId,父id是parentId
//转化后的树形结构数据
getTree(menuList) {
let menus = [];
let sourceMap = {};
menuList.forEach(item => {
item.children = [];
sourceMap[item.menuId] = item;
if (Number(item.parentId) === 0) {
menus.push(item);
} else {
if (sourceMap[item.parentId]) {
if(item.path.indexOf('developing') > -1){
item.development = false;
}else{
item.development = true;
}
sourceMap[item.parentId].children.push(item);
}
}
})
return menus;
},
本文来自博客园,作者:小虾米吖~,转载请注明原文链接:https://www.cnblogs.com/LindaBlog/p/17989219