el-tree 复选框回显问题

<el-tree class="filter-tree" :data="dataTree" :props="defaultProps" :filter-node-method="filterNode" show-checkbox node-key="id" ref="tree" style="height: 50vh;overflow-y: auto;"></el-tree>

watch: {
  filterText(val) {
     this.$refs.tree.filter(val);
  }
},
methods:{
  filterNode(value, data) {
    if (!value) return true;
       return data.label.indexOf(value) !== -1;
    }
}
//编辑回显
showEdit(row) {
   vm.$nextTick(function(){
       this.visibleDia = true;
       this.getTreeList().then(res => {
         if (res && res.length !== 0) {
            this.$refs.tree.setCheckedKeys("返回的子节点id的数组");  //注意,不要带父节点id
          } else {
            this.dataTree = [];
          }
       })
   })
},
// 获取树列表
getTreeList () {
  return new Promise(resolve => {
    this.$http.post({}).then(res => {
      this.dataTree = res.data.treeList;
      resolve(this.dataTree);
    })
  })
},
//提交
submit() {
  console.log(this.$refs.tree.getCheckedKeys()) //当前选中的节点id
  console.log(this.$refs.tree.getHalfCheckedKeys()) //当前半选中状态也就是父节点的id
  var idList =(this.$refs.tree.getCheckedKeys()).concat(this.$refs.tree.getHalfCheckedKeys())
  // 提交接口,分开传选中节点id数组,和选中加半选中状态数组
},
//关闭
close () {
  this.defaultCheckedKeys = this.$refs.tree.setCheckedKeys([]);
  this.visibleDia = false;
},

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值