当前位置: 首页 > news >正文

vxe-table3.0的表格树如何做深层查找,返回搜索关键字的树形结构

vxe-table2.0版本是提供深层查找功能的,因为他的数据源本身就是树形结构,所以深层查找查询出来也是树形结构。
但是vxe-table3.0版本为了做虚拟树功能,将整个数据源由树形垂直结构变成了扁平结构,便不提供深层查询功能,提供的筛选功能筛选出的结果也不如2.0版本,会把筛选目标的所有平均数据一起返回,不理想,那么怎么将2.0版本的深层查找功能用到3.0版本呢?

先看一下2.0版本如何做深层查找的

(1)后端给前端的数据源还要是树形结构。
前端通过js将树形结构转成扁平结构复制给tableData,那么在vxe-table3.0便可以虚拟滚动了。
转换代码:

     treeToList(list) {let res = []for (const item of list) {const { children, ...i } = itemif (children && children.length) {res = res.concat(this.treeToList(children))}res.push(i)}return res},

(2)this.originData = 树形结构表格数据 ,搜索的时候,originData还是树形结构的,2.0版本的XEUtils.searchTree还是可以使用的,搜索结果是树形结构,那么把这个树形结构的搜索结果再转成扁平结构赋给表格,就能得到搜索结果也是虚拟滚动的啦。

思路就是这样:
关键代码:
 

<a-input @change="onSearch" v-model="searchValue" style="width: 280px" placeholder="请输入关键字搜索" /><vxe-table v-if="virtualTree"  show-overflow height="300" ref="xTree" row-id="id" :border="false" :show-header="false" :data="treeData"  :tree-config="{ transform: true,parentField:'pid',childrenField: 'children', expandAll: rootOpened ? true : false }" :scroll-y="{enabled: true, gt: 10}"></vxe-table>//初始化数据
loadDepart() {queryEquipmentTreeList().then((res) => {if (res.success) {this.treeData = []this.originData = XEUtils.clone(arr, true)this.treeData = this.treeToList(arr)if (this.rootOpened) {this.$nextTick(() => {if (this.$refs['xTree']) {this.$refs['xTree'].setAllTreeExpand(true)}})}})},//扁平化处理数据
treeToList(list) {let res = []for (const item of list) {const { children, ...i } = itemif (children && children.length) {res = res.concat(this.treeToList(children))}res.push(i)}return res},//搜索onSearch: XEUtils.debounce(function () {this.dropDownShow = truethis.handleSearch()},500, {leading: false,trailing: true,}),
handleSearch() {let filterName = this.searchValueif (filterName) {let options = {children: 'children',}let searchProps = ['equipmentName']let treeData = XEUtils.searchTree(this.originData,(item) => searchProps.some((key) => item[key].indexOf(filterName) > -1),options)// 搜索之后刷新树this.virtualTree = falsethis.$nextTick(() => {this.virtualTree = true})// 搜索之后默认展开所有子节点this.$nextTick(() => {if (this.$refs.xTree) {this.$refs.xTree.setAllTreeExpand(true)}})this.treeData = [...this.treeToList(treeData)]} else {this.virtualTree = false //用于让树重新加载的标识this.$nextTick(() => {let treeData = this.originDatathis.treeData = [...this.treeToList(treeData)]this.virtualTree = true})}},

如果后端给你的本来就是扁平化的数据,也是一样的,你把他处理成树形结构,在页面循环使用是一样的思路。

http://www.lryc.cn/news/290952.html

相关文章:

  • 幻兽帕鲁越玩越卡,内存溢出问题如何解决?
  • C++_list
  • 使用docker部署mongodb
  • C#,打印漂亮的贝尔三角形(Bell Triangle)的源程序
  • 开源电商系统
  • 责任链模式在java中的实现
  • 粤嵌Gec6818---小项目功能实现简单步骤(RFID+图片显示+音乐+视频)
  • opencv学习 特征提取
  • 关于maven项目构建的解释
  • IMU/捷联惯导常见的术语,以及性能评价标准(附Python解析代码)
  • Debezium发布历史98
  • APUE学习之进程间通信(IPC)(下篇)
  • 【Java 设计模式】行为型之中介者模式
  • MySql 慢SQL配置,查询,处理
  • 算法:分界线
  • STM32单片机基本原理与应用(四)
  • elk之安装和简单配置
  • springboot(ssm环保网站 绿色环保宣传系统Java系统
  • 【MBtiles数据索引和服务发布】GeoServer改造Springboot番外系列二
  • Redis抓取数据到Logstash再推到Elasticsearch集群
  • 【代码随想录-链表】反转链表
  • 32GPIO输入LED闪烁蜂鸣器
  • Qt|QPushButton控件讲解
  • 再学webpack
  • systemd:service与target使用及相关命令
  • FairGuard游戏加固入选《CCSIP 2023中国网络安全行业全景册(第六版)》
  • 文心一言 VS ChatGPT :谁是更好的选择?
  • 七街八巷×实在RPA丨财务凭证录入零出错,效率提升8倍
  • 线性代数----------学习记录
  • Ubuntu如何安装使用Nginx反向代理?