elment 中tree組件展開所有和收縮所有


 

upAll () {
// 全部展開  遍歷變成true

let self = this;
// 將沒有轉換成樹的原數據
let treeList = this.sourceData;
for (let i = 0; i < treeList.length; i++) {
// 將沒有轉換成樹的原數據設置key為... 的展開
self.$refs.selectTree.store.nodesMap[treeList[i].id].expanded = true
}
},

 

上代碼:

<div>
            <iclass="arrow-down el-icon-arrow-down" @click="allExpand(true)" title="展開所有"></i>
            <iclass="arrow-down el-icon-arrow-up" @click="allExpand(false)" titie="收縮所有"></i>

</div>
<el-tree
                    :data="AiditReportData"
                    node-key="id"
                    ref="selectTree"
                    :default-expand-all="true"
                    :default-expanded-keys="defaultExpandArr"
                >

node-key="id"很關鍵

 
  public allExpand(isExpand: boolean) {
      const that: any = this;
      const treeList = this.AiditReportData;
      console.log('isExpand', isExpand);
      for (let i = 0; i < treeList.length; i++) {
        that.$refs.selectTree.store.nodesMap[treeList[i].id].expanded = isExpand;
      }

  }

 


免責聲明!

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



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