/**
* 树形数据搜索 给子节点种上父节点标识,方便找到顶部菜单标识
* @param {arr} tree
* @param {name} string
* @returns {obj}
*/
export function routePathSearch(tree, name) {
let stark = []
stark = stark.concat(tree)
while (stark.length) {
var temp = stark.shift()
if (temp.children) {
stark = stark.concat(temp.children.map(v => { //把数组子元素平铺
// 给子节点种上父节点标识 顶部菜单 标志
if (temp.parentName) {
v.parentName = temp.parentName
} else {
v.parentName = temp.name
}
return v
}))
}
if (temp.name === name) {
return temp
}
}
js树形数据搜索 根据子节点找到父节点 给子节点种上父节点标识,方便找到顶部菜单标识
于 2022-11-03 14:11:01 首次发布