el-tree回显的问题

//   1、直接用:default-checked-keys='checkedKey',将Id push进去,会导致没有全部选中的第二级全部选中

list.forEach(item => {
    this.checkedKey.push(item)
})

//  2、this.$refs.tree.setCheckedKeys(this.defalutArr);

解决方式
setChecked

var that = this
setTimeout(function () {
       list.forEach((value)=>{
       //1. 勾选节点的 key 或者 data 2. boolean 类型,节点是否选中 3. boolean 类型,是否设置子节点 ,默认为 false)如果全部选中setCheckedKeys
          that.$refs.tree.(value, true, false)
       })
},500);

setCheckedKeys

var that = this
let list = []
setTimeout(function () {
     res.data.forEach((value)=>{
         list.push(value.id)
         // that.$refs.tree.setCheckedKeys([])
         // that.$refs.tree.setCheckedKeys(list) 也会导致没有选中的子节点全部选中
         that.$nextTick(() => {
              const nodes = []
              list.forEach(item => {
                  const node = that.$refs.tree.getNode(item);
                  if (node.isLeaf) { //关键,过滤掉不是叶子节点的
                     nodes.push(item)
                  }
               })
               that.$refs.tree.setCheckedKeys(nodes,true)
          })
})
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值