首页 > 其他 > 详细

Q:elementUI中tree组件动态展开

时间:2019-09-16 11:58:30      阅读:391      评论:0      收藏:0      [点我收藏+]

1,在组件中设置展开收缩开关  default-expand-all="isExpand"

技术分享图片

 2,展开收起触发按钮

<div class="tree-foot clearfix">
  <el-button class="fr" size="mini" plain type="primary" icon="el-icon-caret-top" @click="CloseFun">关闭</el-button>
   <el-button class="fr" size="mini" plain type="primary" icon="el-icon-caret-bottom" @click="ExpandFun">展开</el-button>
</div>

3,这里采用ref来获取DOM。至于this.$refs.navtree.toString().split(‘,‘).length为什么不直接获取长度,因为原型对象上没有length方法(再问,我也不知道了)

// 展开收起
  ExpandFun(){
    console.log(this.$refs.navtree[0].store._getAllNodes().length)
    // let type = Object.prototype.toString.call(this.$refs.navtree)
    this.isExpand = true;
    this.DynamicScaling()
  }
  CloseFun(){
    this.isExpand = false;
    this.DynamicScaling()
  }
  DynamicScaling(){
    for(let i=0;i<this.$refs.navtree.toString().split(‘,‘).length; i++){
      for(let j=0; j<this.$refs.navtree[i].store._getAllNodes().length; j++){
        this.$refs.navtree[i].store._getAllNodes()[j].expanded= this.isExpand;
      }
    }
  }

Q:elementUI中tree组件动态展开

原文:https://www.cnblogs.com/chuanq/p/11525938.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!