el-tree回显父节点半选问题

当选中父节点下其中一个子节点时,把父节点和子节点都存储到库中做顶部菜单展示,回显时使用以下方法进行半选展示。

<el-tree

                    ref="menuTree"

                    :data="treeData"

                    :default-checked-keys="checkedKeys"

                    :check-strictly="false"

                    :props="defaultProps"

                    :filter-node-method="filterNode"

                    class="filter-tree"

                    node-key="id"

                    highlight-current

                    show-checkbox

                  />

选中方法:

updatePermession() {

      this.menuIds = "";

      this.menuIds = this.$refs.menuTree.getCheckedKeys().join(',').concat(',').concat(this.$refs.menuTree.getHalfCheckedKeys().join(','))//全选半选都存到库中

      // this.menuIds = this.$refs.menuTree

      //   .getCheckedKeys()

      //   .join(",")

      //   .concat(",");

      console.log("菜单");

      console.log(this.menuIds);

      this.scopdata = this.$refs.dataTree.getCheckedKeys();

      permissionUpd(this.$route.query.roleId, this.menuIds, this.scopdata).then(

        () => {

          this.newSuccess();

        }

      );

    },

 

fetchRoleTree获取到库中存的父节点id和子节点的id,回显方法

fetchRoleTree(this.$route.query.roleId).then(res => {

      console.log(res.data + "eeeeeee");

      //this.checkedKeys = res.data;

      res.data.forEach((i,n) => {

       var node=this.$refs.menuTree.getNode(i);

       if(node.isLeaf){

        this.$refs.menuTree.setChecked(node, true);//是否设置子节点,默认为false,利用tree组件渲染后带有的isLeaf(是否为叶子节点)属性,如果为叶子节点就选中。利用tree的API就实现了正确的回显效果

      }

      })

    });

 

 

参考:https://blog.csdn.net/xudalin/article/details/103158941

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值