>》>》>》>》

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

  }

 

posted @ 2019-12-07 17:47  大、锤  阅读(2451)  评论(0编辑  收藏  举报