el-table 树状表格查询符合条件的数据

需要对el-table的树状表格根据输入机构名称,筛选出符合条件的数据,可用如下方法:

页面内容如下:

html 复制代码
<el-input v-model="ogeName" placeholder="请输入机构名称">

<el-table :data="list" row-key="id" :tree-props="{children:'children',hasChildren:'hasChildren'">
    <el-table-column label="机构名称" prop="attributes.org_name"></el-table-column>
</el-table>

数据格式如下:

javascript 复制代码
   data() {
      return {
        data: [{
          attributes:[org_name:'1'],
          hasChildren: true,
          label: '一级 1',
          children: [{
            attributes:[org_name:'1'],
            hasChildren: true,
            label: '二级 1-1',
            children: [{
              attributes:[org_name:'1'],
              hasChildren: false,
              label: '三级 1-1-1'
            }]
          }]
        }],
      };
    },

具体筛选方法如下:

javascript 复制代码
// 查询
handleSearch() {
    let list = this.list
    let lastList = this.handleTreeData(list,this.orgName)
    this.list = lastList
}
// 筛选数据
handleTreeData(treeData,filterValue) {
    if (!treeData || treeData.length !== 0) {
        return []
    }
    const data = []
    for (let i = 0; i < treeData.length; i++) {
        let match = false
        for (const pro in treeDate[i]) {
            if (pro === 'label') {
                match |= treeData[i][pro].includes(filterValue)
                if (match) break
            }
        if (this.handleTreeData(treeData[i].children,filterValue).length > 0 || match) {
            data.push({ ...treeData[i],children: this.handleTreeData(treeData[i].children,filterValue})
        }
        return data
}
相关推荐
前端君4 小时前
实现最大异步并发执行队列
javascript
知识分享小能手5 小时前
React学习教程,从入门到精通,React 组件核心语法知识点详解(类组件体系)(19)
前端·javascript·vue.js·学习·react.js·react·anti-design-vue
蚂蚁RichLab前端团队6 小时前
🚀🚀🚀 RichLab - 花呗前端团队招贤纳士 - 【转岗/内推/社招】
前端·javascript·人工智能
萌萌哒草头将军7 小时前
Oxc 和 Rolldown Q4 更新计划速览!🚀🚀🚀
javascript·vue.js·vite
Qlittleboy7 小时前
uniapp如何使用本身的字体图标
javascript·vue.js·uni-app
小白菜学前端7 小时前
vue2 常用内置指令总结
前端·vue.js
林_深时见鹿7 小时前
Vue + ElementPlus 自定义指令控制输入框只可以输入数字
前端·javascript·vue.js
GDAL7 小时前
Knockout.js 任务调度模块详解
javascript·knockout
椒盐螺丝钉7 小时前
Vue组件化开发介绍
前端·javascript·vue.js
koooo~7 小时前
v-model与-sync的演变和融合
前端·javascript·vue.js