在树形结构中搜索 checkItems值为 某某某的数据,返回的是子数据。
const searchTree = (tree, checkItems) => {
let res = '';
let state = false;
const readTree = (_tree, _checkItems) => {
if (state) return;
for (let i = 0; i < _tree.length; i++) {
if (_tree[i].checkItems === _checkItems) {
state = true;
res = _tree[i];
} else {
_tree[i].children !== null && readTree(_tree[i].children, _checkItems);
}
}
};
readTree(tree, checkItems);
return res;
};
标签:readTree,res,tree,js,state,树形,搜索,let,checkItems
From: https://www.cnblogs.com/ZerlinM/p/17350388.html