当前位置: 移动技术网 > IT编程>网页制作>HTML > elementui tree设置节点半选解决方案

elementui tree设置节点半选解决方案

2020年07月24日  | 移动技术网IT编程  | 我要评论

问题1

tree组件在获取完数据进行页面回显时,因为获取的数据中包含父节点的关系,把不该选中的子节点也全部勾上了。

解决方案

isLeaf(判断节点是否为叶子节点)

getNode(获取tree中对应的节点)

setChecked (设置tree中对应的节点为选中状态)

 
let res = [1,11,23,25,28,37];
res.map((i, n) => {
     //根据i获取tree中的节点
     var node = that.$refs.menuListTree.getNode(i);
     if (node.isLeaf) {
          //设置某个节点的勾选状态
          that.$refs.menuListTree.setChecked(node, true);
      }
});

 

问题2

子节点未全部选中时,.checkedKeys中没有包含父节点id。

解决方案

halfCheckedKeys中为半选中的节点(具体可查看官方API)

//复选框点击
checkboxSelect(data, status) {
  this.childId = status.checkedKeys; //用于选中时候的前端页面回显
  this.allIdArr = status.checkedKeys.concat(status.halfCheckedKeys); //传给后台的数据
},

 

本文地址:https://blog.csdn.net/weixin_40881970/article/details/107536469

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网