ts 遍历树形数组 找出某一项
function deepQuery(tree:any,id:any){ let isGet = false; let retNode = {title:''}; function deepSearch(tree:any,id:any){ for(var i = 0;i<tree.length;i++){ if(tree[i].children && tree[i].children.length > 0){ deepSearch(tree[i].children,id); } if(id === tree[i].id || isGet){ isGet || (retNode = tree[i]); isGet = true; break; } } }
deepSearch(tree,id);
return retNode;
}
转载自:https://www.benbonben.com/