鍍金池/ 問答/HTML5  HTML/ element-ui 怎樣動態(tài)控制樹的全部折疊和展開

element-ui 怎樣動態(tài)控制樹的全部折疊和展開

1.點擊按鈕,全部展開,然后el-tree則全部展開
2.點擊按鈕,全部折疊,然后el-tree則全部折疊
3.使用 :default-expand-all="isExpand",動態(tài)改變isExpand的值,值變化,樹卻沒有變化
4.怎么實現(xiàn)?
html代碼:
<el-tree

  class="filter-tree treeoverflow"
  :data="data2"
  :props="defaultProps"
  highlight-current
  :filter-node-method="filterNode"
  @node-click="handleNodeClick"
  :default-expand-all="isExpand"
  ref="tree2">
</el-tree>

js代碼:

  isExpand(){
  console.log('執(zhí)行isExpand()');
  this.czlx=this.$store.state.ysml.czlx;
  if( this.czlx=='111') {
    console.log("全部折疊"+this.czlx);
    this.iscolspann=false;
    return false;
  }else if( this.czlx=='222'){
    console.log("全部展開");
    this.iscolspann=true;
    return true;
  }else{
    return false;
  }
},
回答
編輯回答
傲嬌范

this.$refs.tree2.$el里面帶有樹形結(jié)構(gòu),可以找打你要的操作

2017年3月28日 02:16
編輯回答
伐木累
for(var i=0;i<this.$refs.treeX.store._getAllNodes().length;i++){
           this.$refs.treeX.store._getAllNodes()[i].expanded=this.isexpand;
        }
    this.$refs.treeX是樹對象,通過樹對象獲取所有的樹節(jié)點,遍歷樹節(jié)點設(shè)置expand屬性為true則全部展開,設(shè)置為false則全部收起,注意節(jié)點要設(shè)置id
2017年5月27日 13:49