在多级 jsTree 中,如何选择特定节点(可能是叶节点)并展开它的所有父节点?
示例:
从这个 JSFiddle ( http://jsfiddle.net/mmeah/fyDE6/ ) 我想以编程方式选择 Grand Child 并打开所有父节点。
在某些情况下,如果用户通过深层链接进入我的网站,我会尝试确保用户返回到树中的正确节点
最佳答案
jsTree 给出了一个 open_node() 函数来任意触发任意节点打开。只需扫描树中未打开的父项并打开它们即可。
例子: http://jsfiddle.net/mmeah/yyy8W/
$("#findChild").click(function(){
$.jstree._reference(myTree).open_node("#Node_001",function(){;},false);
});
$("#findGrandChild").click(function(){
var closedParents = $("#Node_003").parents("li.jstree-closed");
for(var i=closedParents.length-1;i>=0;i--){
pleaseOpen($(closedParents[i]));
}
});
function pleaseOpen(thisNode){
if(typeof thisNode=="undefined") return;
if(thisNode.hasClass("jstree-leaf") || thisNode.hasClass("jstree-open") ) return;
$.jstree._reference(myTree).open_node(thisNode,function(){;},true);
}
关于javascript - 如何以编程方式选择 jsTree 中的节点并打开所有父节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12013785/