js 遍历数据结构,使不符合条件的全部删除
let newSource=JSON.parse(JSON.stringify(state.treeData))state.expandedKeys=[]checkedKeys.map((item:any)=>{loop(newSource,{jsonPath:item.split('&')[1]},state.expandedKeys)})function removeUnwantedNodes(tree) {// 检查当前节点是否满足条件if (!tree.newTag) { // 根据你的实际条件修改这里return null; // 不满足条件,则返回null,后续会过滤掉}// 如果有子节点,则递归处理子节点if (Array.isArray(tree.children)) {tree.children = tree.children.map(child => removeUnwantedNodes(child)).filter(Boolean);}// 返回经过处理后的当前节点return tree;}newSource = newSource.map(node => removeUnwantedNodes(node)).filter(Boolean);state.selectTreeData=newSource
样例如下