Ant-design: Tree选中项

Created on 16 May 2016  ·  3Comments  ·  Source: ant-design/ant-design

Tree获取选中项时,能否把选中项的父节点以及父节点的父节点全部获取,比如三级菜单,最后一级叶子节点选中后,获取选中项前面2项获取不到

Most helpful comment

let sel = [];
function findPath(selected, children, parent = { root: true }) {
  for (var i = 0; i < children.length; i++) {
    const item = children[i];
    if (selected === item.key) {
      sel.push(item);
      return;
    }
    if (item.children) {
      findPath(selected, item.children, item);
      if (sel.length) {
        sel.push(item);
        return;
      }
    }
  }
}

All 3 comments

let sel = [];
function findPath(selected, children, parent = { root: true }) {
  for (var i = 0; i < children.length; i++) {
    const item = children[i];
    if (selected === item.key) {
      sel.push(item);
      return;
    }
    if (item.children) {
      findPath(selected, item.children, item);
      if (sel.length) {
        sel.push(item);
        return;
      }
    }
  }
}

问题解决了吗?先关闭

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yangbin1994 picture yangbin1994  ·  3Comments

xtznhzxdev picture xtznhzxdev  ·  3Comments

PeteAndersen picture PeteAndersen  ·  3Comments

Orbyt picture Orbyt  ·  3Comments

tangsj picture tangsj  ·  3Comments