function findObjectById(obj, id, result) {
复制
if (obj.id === id) { result.push(obj); } if (obj.children && obj.children.length > 0) { for (let i = 0; i < obj.children.length; i ) { findObjectById(obj.children[i], id, result); } } }
let result = []; findObjectById(treeData, 1, result);
console.log(result); // 结果存储在result变量中