function findPathByLeafId(keys,leafId, nodes, path) {
if(path === undefined) {
path = [];
}
for(var i = 0; i < nodes.length; i++) {
var tmpPath = path.concat();
tmpPath.push({
...nodes[i],
children:[]
});
if(leafId == nodes[i][keys]) {
return tmpPath;
}
if(nodes[i].children) {
var findResult = findPathByLeafId(keys,leafId, nodes[i].children, tmpPath);
if(findResult) {
return findResult;
}
}
}
}
const treeData = [{
id:1,
label:"a",
children:[{
id:12,
label:"b",
children:[{
id:123,
label:"c",
children:[]
}]
}]
}]
let id = 123
let a = findPathByLeafId("id", id , treeData);
console.log('溯源后的数组====>>>',a)