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;
        }
      });
    },
Logo

前往低代码交流专区

更多推荐