- 优化 tree,查找问题,undefined异常

This commit is contained in:
sin
2019-03-13 00:15:14 +08:00
parent 3575c6255c
commit 0c8a79a8ed
4 changed files with 6 additions and 27 deletions

View File

@@ -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;