//arr数据大致长这样
arr=[
{
a:1,
childrenn:[
{
a:1-1,
childrenn:[
{a:1-2,},
{a:1-2-2,}
]
},
]
},
{
a:2,
childrenn:[
{
a:2-1,
},
]
},
{
a:3,
},
]
//父节点遍历一次 拿chlidren去遍历子节点
arr.forEach(rootNode=>{
let nodeModels = {
path: rootNode.uri,
name: rootNode.text,
component: rootNode.cls,
meta: rootNode.iconCls,
children: [],
redirect:rootNode.children.length>0?rootNode.children[0].uri:''
};
nodeModels.children.push(getChinld(rootNode.children));
menuArr.push(nodeModels);
});
// 遍历子级节点
function getChinld(childNode) {
let childArray = [];
for(var i=0;i<childNode.length;i++){
let nodeModel = {
path: childNode[i].uri,
name: childNode[i].text,
component: childNode[i].cls,
meta: childNode[i].iconCls,
children: [],
redirect:childNode[i].children.length>0?childNode[i].children[0].uri:'',
};
nodeModel.children.push(getChinld(childNode[i].children));
childArray.push(nodeModel);
}
return childArray;
}
console.log(menuArr); //获取到遍历的样子啦
console.table(menuArr);