我如何以编程方式在jsTree中选择一个节点并打开所有父级 [英] How do I programmatically select a node in jsTree and open all parents

查看:327
本文介绍了我如何以编程方式在jsTree中选择一个节点并打开所有父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在多级jsTree中,如何选择特定节点(可能是叶节点)并扩展其所有父节点? 示例:
通过这个JSFiddle( http://jsfiddle.net/mmeah/fyDE6/),我想以编程方式选择Grand Child,并拥有所有父节点已打开.

In a multi-level jsTree how do I select a particular node (probably a leaf node) and expand all it's parents? Example:
From this JSFiddle (http://jsfiddle.net/mmeah/fyDE6/) I want to programmatically select Grand Child and have all parent nodes opened.

在某些情况下,我试图确保用户遵循深层链接进入我的网站,从而返回到树中的正确节点

For some context I'm trying to ensure the user returns to the correct node in the tree if they follow a deep link into my site

推荐答案

jsTree提供了open_node()函数来任意触发任何节点打开.只需在树上扫描未打开的父母并打开它们即可.

jsTree gives an open_node() function to arbitrarily trigger any node to open. Just scan the tree for non-open parents and open them.

示例: 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);
}

这篇关于我如何以编程方式在jsTree中选择一个节点并打开所有父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆