- 树结构转换成数组
treeToArray(tree) {
let arr = [];
let expand = (tree) => {
if(tree&&tree.length>0) {
tree.forEach(el => {
arr.push(el);
expand(el.children);
});
}
}
return arr;
}
2.筛选树节点checked=true的数据
filterArr(arr) {
return arr.filter((item)=>{
return item.checked === true;
}).map((item)=>{
item = Object.assign({},item);
if(item.children&&item.children.length>0) {
item.children = this.filterArr(item.children);
}
return item;
})
}
网友评论