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);
过滤出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));