data() {
return {
treeData: [],
treeData: [
{
name: 'aa',
id: '1'
children: [{name: 'ab', id: '11', children:undefined}]
}
]
}
},
method: {
filterTreeData(row) {
this.treeData= row ?this.returnFilter(JSON.parse(JSON.stringify(this.treeDataAll)),row,'-1'):JSON.parse(JSON.stringify(this.treeDataAll))
},
returnFilter(data,row,isTop) {
const arr= []
const list= [...data]
list.forEach(item => {
item.isShow= false
if (item['children']) {
const children= this.returnFilter(item.children,row)
item.isShow= children.isShow
item.children= children.list
}
if (item.name.includes(row)|| item.isShow) {
arr.push(item)
}
})
if (isTop === '-1') {
return arr
}else {
if (arr.length> 0) {
return { list: arr, isShow: true }
}
return { list: arr, isShow: false }
}
}
}