element-ui 表格樹形數據 的展示和收起


<template>
      //row-key 和ref 要必須寫
 <el-table
  v-loading="load"
  element-loading-text="加載數據中"
  ref="theTable"
  :data="tableList"
  style="width: 100%"
  :row-key="add"
  :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
  ></el-table>
  ......
</template>
method:{
     //篩選
    screenclick() {
      //點擊篩選的時候 讓篩選出來的數據展開
      this.forArr(this.tableList, false);
      this.getList();
    },
      // 重置
    Resetdata() {
      this.textval = "";
      //重置的時候 讓數據全部收起
      this.forArr(this.tableList, false);
      this.getList();
    },
    //列表展開和收起
    forArr(arr, isExpand) {
      arr.forEach(i => {
        this.$refs.theTable.toggleRowExpansion(i, isExpand);
        if (i.children) {
          this.forArr(i.children, isExpand);
        }
      });
    },
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM