其他分享
首页 > 其他分享> > elment 中tree组件展开所有和收缩所有

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;
      }

  }

 

标签:expanded,isExpand,refs,所有,tree,elment,let,treeList,id
来源: https://www.cnblogs.com/ll15888/p/12002745.html