function getTreeMenu(rootList, id, list) {
for (let i = 0; i < rootList.length; i++) {
let item = rootList[i]
if (String(item.parentId.slice().pop()) == String(id)) {
list.push(item._doc)
}
}
list.forEach(item => {
item.children = []
getTreeMenu(rootList, item._id, item.children)
if (item.children.length) {
delete item.children
} else if (item.children.length > 0 && item.children[0].menuType == 2) {
item.action = item.children
delete item.children
}
})
return list
}
- 请问这块为什么判断 children 数组中的第一个就能判断后面的元素都是按钮?