代码之家  ›  专栏  ›  技术社区  ›  heyhoo

角度树组件|获取路径

  •  0
  • heyhoo  · 技术社区  · 8 年前

    当我点击一个节点时,有人知道我如何获得完整的路径吗。 我在API中看到了一个路径选项,但我不知道如何在click事件中使用它。

    options: ITreeOptions = {
     actionMapping: {
      mouse: {
        dblClick: (tree, node, $event) => {
    
        }
      }
     }
    }
    
    1 回复  |  直到 8 年前
        1
  •  2
  •   LLai    8 年前

    根据您需要的格式,您可以自己构建血统/路径

    options: ITreeOptions = {
        actionMapping: {
            mouse: {
                dblClick: (tree, node, $event) => {
                    const lineage = [];
                    // add clicked node as first item
                    lineage.push(node.data);
    
                    // grab parent of clicked node
                    let parent = node.parent;
    
                    // loop through parents until the root of the tree is reached
                    while(parent !== null){
                        lineage.push(parent.data);
                        parent = parent.parent;
                    }
                }
            }
        }
    }
    
    推荐文章