- 优化 tree,查找问题,undefined异常
This commit is contained in:
@@ -20,15 +20,13 @@ function findNodes(id, nodes) {
|
||||
if (node.key === id) {
|
||||
res.push(node.key);
|
||||
break;
|
||||
} else {
|
||||
} else if (node.children) {
|
||||
const childNodes = findNodes(id, node.children);
|
||||
if (childNodes.length) {
|
||||
res.push(node.key);
|
||||
for (let j = 0; j < childNodes.length; j += 1) {
|
||||
res.push(childNodes[j]);
|
||||
}
|
||||
break;
|
||||
res.push(node.key);
|
||||
for (let j = 0; j < childNodes.length; j += 1) {
|
||||
res.push(childNodes[j]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
||||
Reference in New Issue
Block a user