树状菜单递归循环遍历获取响应数据,可以顺便重定向

六月ゝ 毕业季﹏ 提交于 2020-01-03 21:25:05
//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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!