0

我正在使用 IGtree。我在树中有数据,直到树中有 4 个级别。最初所有节点都被折叠。在扩展任何特定节点时,其所有子节点也应扩展至最后一级

4

2 回答 2

2

一种选择是处理 nodeExpanding 事件以区分根节点并找到它们的子节点,它们是父节点。然后将每个节点和所有节点展开到根节点。这里作为代码片段:

$(document).on("igtreenodeexpanding", "#tree", function (evt, ui) {
    // this ensures the expanding node is on root level.
    if (ui.node.path.indexOf(ui.owner.options.pathSeparator) <= -1) {
        // Select all the nodes whcih contain children
        // Here you can play with the path if you want to limit expanding to a certain level
        var nodes = $(ui.node.element).find("li[data-role='node'].ui-igtree-parentnode");
        for (var i = 0; i < nodes.length ; i++) {
            var node = $(nodes[i]);
            ui.owner.expand(node);
            ui.owner.expandToNode(node);
            // or you can use: 
            // $("#tree").igTree("expand", node);
            // $("#tree").igTree("expandToNode", node);
        }
    }
});

希望有帮助。

于 2019-04-05T12:30:42.720 回答
1
let nodes = $("#configTree").igTree("children", event.element);
  if(nodes) {
    nodes.forEach((node1)=>{
      $("#configTree").igTree("expand", node1.element);
    })
  }
于 2019-04-12T08:48:24.987 回答