树形三级菜单,去掉多余字段,只保留title、index、children三个字段

let arr = [];
let child = [];
menu.forEach(function(item){
  arr.push({title: item.title, index: item.index,children:item.children});
});
arr.forEach(ol=>{
  ol.children.forEach(el=>{
    ol.children.push({title: el.title, index: el.index,children:el.children});
  });
  ol.children = ol.children.filter(item => !item.Id);  //过滤掉含有menuId的数据
  child = ol.children;
  child = child.filter(item => item.children.length>0);
  child.forEach(index=>{
    index.children.forEach(i=>{
      index.children.push({title: i.title, index: i.index});
    });
    index.children = index.children.filter(item => !item.Id);
  })
});

你可能感兴趣的:(树形三级菜单,去掉多余字段,只保留title、index、children三个字段)