getPathByKey (value, key, arr) {
//测试数据
let temppath = [];
let realPath = ""
try {
function getNodePath(node,index) {
temppath.push(index);
//找到符合条件的节点,通过throw终止掉递归
if (node[key] === value) {
temppath.forEach((v, i) => {
if (i == 0) {
realPath += "." + v
} else {
realPath += `.children.${v}`
}
})
// temppath = temppath.join(",")
throw ("GOT IT!");
// return;
}
if (node.children && node.children.length > 0) {
for (var i = 0; i < node.children.length; i++) {
getNodePath(node.children[i],i);
}
//当前节点的子节点遍历完依旧没找到,则删除路径中的该节点
temppath.pop();
} else {
//找到叶子节点时,删除路径当中的该叶子节点
temppath.pop();
}
}
for (let i = 0; i < arr.length; i++) {
getNodePath(arr[i],i);
}
} catch (e) {
return realPath;
}
},



