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

  }

 

上一篇:elment-ui文件上传详解


下一篇:Qt入门系列开发教程【基础控件篇】QSpinBox旋转框