2022.5.19 树形结构数据 获取每个节点的最后一个节点

·  阅读 34
let arr = [  {    label: "目录",    children: [{ label: "菜单", children: [{ label: "按钮" }] }],
  },
  {
    label: "目录",
    children: [{ label: "菜单", children: [{ label: "按钮" }] }],
  },
];
let btnList = [];
function fox(data) {
  for (var i = 0; i < data.length; i++){
    var _list = data[i]
    if (_list.children && _list.children.length > 0) {
       fox(_list.children)
    } else {
      btnList.push(_list)
    }
  
  }
   
}
fox(arr)
 console.log(btnList);
复制代码

image.png

过滤出type != '03'的数据

      var newTree = data.filter((item) => item.meta.type != '03');
      newTree.forEach(
        (item) => item.children && (item.children = filterTree(item.children))
      );
      return newTree;
    }
    console.log(filterTree(menuList));
复制代码
分类:
前端
标签:
收藏成功!
已添加到「」, 点击更改