js树形结构中搜索某一项数据
在树形结构中搜索 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;
};