首页 > 其他 > 详细

element tree递归获取所有父级id

时间:2021-07-15 17:15:26      阅读:9      评论:0      收藏:0      [点我收藏+]

data里面定义三个变量

rowList: [],
parentList: [],
//最终结果
reqlist: [],    

tree节点点击事件

handleNodeClick(data, node) {
      this.getParent(node);
    //同级tree点击时置空,也可以判断
      this.reqlist = this.rowList;
      this.rowList = [];
      console.log(this.reqlist);
    },

递归代码

getParent(node) {
      var that = this;
      if (node.parent && !Array.isArray(node.parent.data)) {
        node.parent.data instanceof Object && that.rowList.push(node.data.id);
        that.getParent(node.parent);
      } else if (that.rowList.length === 0) {
        if (that.parentList.length === 0) {
          that.rowList.push(node.data.id);
        }
      } else {
        that.rowList.push(node.data.id);
      }
    },

最后reqlist就是自己包括所有父级的id

element tree递归获取所有父级id

原文:https://www.cnblogs.com/nicelife/p/15015924.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!