我正在使用IGtree。我在树中的数据直到树中的4个级别。最初所有节点都已折叠。在扩展任何特定节点时,其所有子节点也应该扩展到最后一级
其中一个选项是处理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);
}
}
});
希望有所帮助。
let nodes = $("#configTree").igTree("children", event.element);
if(nodes) {
nodes.forEach((node1)=>{
$("#configTree").igTree("expand", node1.element);
})
}