js 前端多层树型结构做搜索功能 前端如何做搜索、过滤、filter、map

前端如何做搜索,多层树形结构怎么过滤

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

猜你喜欢

转载自blog.csdn.net/z00001993/article/details/106164208