vue中调用element-ui el-table树形数据中如何获取选定行的父节点

vue中调用element-ui el-table树形数据中如何获取选定行的父节点

核心在于使用递归遍历

getTreeTableParentRow(baseRow, row) {
      let prow = null;
      let children = baseRow.children;
      if (children && children.length > 0) {
        children.forEach((item) => {
          if (row == item) {
            prow = baseRow;
          } else {
            prow = this.getTreeTableParentRow(item, row);
          }
        });
      }
      return prow;
    },

// 获取到点击
handleClickRow(row) {
let prow = {};
      this.tableData.forEach((item) => {
        prow = this.getTreeTableParentRow(item, row);
        if (prow) {
          return;
        }
      });
    },

你可能感兴趣的:(vue.js,javascript,前端,elementui)