前端如何做搜索,多层树形结构怎么过滤
const arr = [
{
name:'第一层',
children:[
{name:'第一层的孩子',children:[name:'第二层的孩子']}
]
}
...
]
html...
<el-input v-model="category_name" size="small" placeholder="分类名称" maxlength="8">
<el-button slot="append" icon="el-icon-search" @click="searchCategory_name" />
</el-input>
javescript...
async searchCategory_name() {
if (this.category_name !== '') {
this.tableData = await this.searchData(this.cloneTableData, this.category_name);
}
},
searchData(data, val) {
return data.filter(function f(o) {
if (o.category_name.includes(val)) return true
if (o.children) {
return (o.children = o.children.filter(f)).length
}
})
},