前端如何做搜索,多层树形结构怎么过滤
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
}
})
},
不私藏,献上开发宝典:http://raboninco.com/1MsLW
版权声明:本文为z00001993原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。