// 递归获取树子节点路径
getNodePath (treeData, nodeId, indexArray) {
let arr = Array.from(indexArray)
for (let i = 0, len = treeData.length; i < len; i++) {
arr.push(treeData[i].name)
if (treeData[i].id === nodeId) {
return arr;
}
let children = treeData[i].lists;
if (children && children.length) {
let result = this.getNodePath(children, nodeId, arr)
if (result) return result
}
arr.pop();
}
return false
}
网友评论