javascript - 如何以编程方式选择 jsTree 中的节点并打开所有父节点

标签 javascript jquery jquery-ui jstree

在多级 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/

相关文章:

javascript - 2 var 数组在我更改 arrayToDataTable 输入后神秘地改变(谷歌图表线)

jquery - 未注入(inject) Chrome 扩展样式

javascript - 为什么 Atom 文档使用 CoffeeScript,却用 JavaScript 生成包?

javascript - 如何使用浏览器创建浏览器页面?

c# - 如何使用 Selenium ExecuteScript 函数获取 HashTable

jquery - 模板 ruby​​ 字符串评估错误?

javascript - jQuery UI Sortable Widget动态添加列表不触发事件

javascript - 在动态创建的元素上的单击事件监听器上包含子元素

javascript - 在 spring mvc 的某个时间后关闭 jquery ui 弹出窗口后必须重定向 html 页面

javascript - 在悬停时更改背景位置 - jquery