0
点赞
收藏
分享

微信扫一扫

获取树节点的父属性拼接字段

color_小浣熊 2022-03-11 阅读 97

项目场景:

拼接点击的树节点的所有父节点的name属性 ![在这里插入图片描述](https://img-blog.csdnimg.cn/54f9d13df08d421da7236334aaad2197.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA6ZOB6KGA54yq5Yia6ayj,size_17,color_FFFFFF,t_70,g_se,x_16) ![在这里插入图片描述](https://img-blog.csdnimg.cn/67c09723ee1843779030345032b8289f.png)
# 代码片段:
   handleNodeClick(data, node, value) {
        this.getTreeNode(this.$refs.treeList.getNode(data.nodeId), "");
    },

//获取父属性并拼接
    getTreeNode(node, xx) {

      if (node.parent.data.nodeName) {
        xx = node.parent.data.nodeName + "-" + xx;
        this.getTreeNode(node.parent, xx);
      } else {
        this.ruleForm.orgName = xx.slice(0, xx.length - 1);
        this.$refs.popoverRef.doClose();
      }
    },


完整代码:

        <el-tree
              ref="treeList"
              :data="treeOption"
              highlight-current
              :render-content="renderContent"
              :expand-on-click-node="false"
              node-key="nodeId"
              :check-on-click-node="true"
              :current-node-key="ruleForm.orgId"
              :default-expanded-keys="[ruleForm.orgId]"
              :props="{
                children: 'children',
                label: 'nodeName'
              }"
              @node-click="handleNodeClickT"
            />
   handleNodeClickT(data, node, value) {
      // console.log("aaaa", data, this.$refs.treeList.getNode(data.nodeId));
      // const { tree } = this.$refs;
      // 选中节点的所有父级id和codeItem信息

      if (data.nodeType === 2) {
        this.$refs.treeList.setCurrentKey(data.nodeId);
        // console.log("ccc", this.$refs["treeList"], "ddd", this.$refs.treeList);

        this.ruleForm.orgId = data.nodeId;
        this.ruleForm.pointName = data.nodeName;
        //
        this.getTreeNode(this.$refs.treeList.getNode(data.nodeId), "");
        // this.$parent.handleNodeClick(data);
      } else {
        this.$refs.treeList.setCurrentKey(this.ruleForm.orgId);
        // this.$refs.tree.setCurrentKey(null);
      }
    },
    // 点击节点

    getTreeNode(node, xx) {

      if (node.parent.data.nodeName) {
        xx = node.parent.data.nodeName + "-" + xx;
        this.getTreeNode(node.parent, xx);
      } else {
        this.ruleForm.orgName = xx.slice(0, xx.length - 1);
        this.$refs.popoverRef.doClose();
      }
    },


举报

相关推荐

0 条评论