element tree递归获取所有父级id

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

上一篇:centos强制关机后,网卡无法启动


下一篇:Greenplum行列转换操作