Ant-design: Tree选中项

创建于 2016-05-16  ·  3评论  ·  资料来源: ant-design/ant-design

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

最有用的评论

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;
      }
    }
  }
}

所有3条评论

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;
      }
    }
  }
}

问题解决了吗?先关闭

此线程已被自动锁定,因为它最近没有活动。 请为相关错误打开一个新问题并链接到此线程中的相关评论。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

tianyacsdn picture tianyacsdn  ·  3评论

cnchore picture cnchore  ·  3评论

ericdai picture ericdai  ·  3评论

longzb picture longzb  ·  3评论

plandem picture plandem  ·  3评论