let treeList = [{id: '1',name: '父一',children: [{id: '1-1',name: '子一',children: [{ id: '1-1-1', name: '孙一一', children: null },{ id: '1-1-2', name: '孙一二', children: null },{ id: '1-1-3', name: '孙一三', children: null }]},]},{id: '2',name: '父二',children: [{ id: '2-1', name: '子二一', children: null },{ id: '2-2', name: '子二一', children: null },{ id: '2-3', name: '子二一', children: null }]},{id: '3',name: '父三',children: null}
]function find(treeList,code) {for(let i in treeList){if (treeList[i].id == code) {return treeList[i].name}if(treeList[i].children){let node = find(treeList[i].children,code)console.log(node + '这是node');if (node !== undefined) {return node.concat(treeList[i].name)}}}
}
console.log(find(treeList,'1-1-1'));