递归遍历树结构,根据条件删除树的某些节点
根据条件删除树的某些节点。示例中条件为:grade !== 1
function filterTree (data) { var newTree = data.filter(x => x.grade !== 1) newTree.forEach(x => x.children && (x.children = filterTree(x.children))) return newTree }
根据条件删除树的某些节点。示例中条件为:grade !== 1
function filterTree (data) { var newTree = data.filter(x => x.grade !== 1) newTree.forEach(x => x.children && (x.children = filterTree(x.children))) return newTree }