jsTree - 在loaded.jstree 事件中获取选定的节点

发布于 2024-12-14 03:07:55 字数 315 浏览 5 评论 0原文

如何在loaded.jstree事件中获取选定的节点?

我应该在事件处理程序中做什么:

    $('#Tree').bind('loaded.jstree', function(event, data){//TODO: How to get the selected node here?}).jstree();

顺便说一句,我发现事件数据arg对象包含一个名为get_selected()的函数,但无法从中获取任何内容。

我的目的是将客户端重定向到当前选定的节点(通过“url”属性)。

提前致谢

How can I get the selected node on the loaded.jstree event?

what should I do in the event handler:

    $('#Tree').bind('loaded.jstree', function(event, data){//TODO: How to get the selected node here?}).jstree();

By the way, I found out that the event data arg object contains a function called get_selected() but couldn't get anything from it.

My purpose is to redirect the client to the current selected node (by 'url' attribute).

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没有心的人 2024-12-21 03:07:55

似乎根据此处演示的文档:

http://www.jstree.com/demo

你可以执行以下操作:

.one("reselect.jstree", function (event, data) { });

.bind("select_node.jstree", function (event, data) {  
                // `data.rslt.obj` is the jquery extended node that was clicked 
                alert(data.rslt.obj.attr("id")); 
            })

仔细阅读文档:

使用一个,这是因为如果调用 refresh ,这些事件将被调用
触发

// 1) if using the UI plugin bind to select_node
        .bind("select_node.jstree", function (event, data) { 
            // `data.rslt.obj` is the jquery extended node that was clicked
            alert(data.rslt.obj.attr("id"));
        })
        // 2) if not using the UI plugin - the Anchor tags work as expected
        //    so if the anchor has a HREF attirbute - the page will be changed
        //    you can actually prevent the default, etc (normal jquery usage)
        .delegate("a", "click", function (event, data) { event.preventDefault(); })

,如果您不使用 UI 插件,则可以正确地进行重定向,而不是编写 event.preventDefault();,并编写: window.location = $(this).attr('href');

Seems according to the documentation of the demo here :

http://www.jstree.com/demo

you can do :

.one("reselect.jstree", function (event, data) { });

or

.bind("select_node.jstree", function (event, data) {  
                // `data.rslt.obj` is the jquery extended node that was clicked 
                alert(data.rslt.obj.attr("id")); 
            })

Read carefully the documentation as :

one is used, this is because if refresh is called those events are
triggered

// 1) if using the UI plugin bind to select_node
        .bind("select_node.jstree", function (event, data) { 
            // `data.rslt.obj` is the jquery extended node that was clicked
            alert(data.rslt.obj.attr("id"));
        })
        // 2) if not using the UI plugin - the Anchor tags work as expected
        //    so if the anchor has a HREF attirbute - the page will be changed
        //    you can actually prevent the default, etc (normal jquery usage)
        .delegate("a", "click", function (event, data) { event.preventDefault(); })

For the last event delegate, instead of writing event.preventDefault();, you can make your redirection correctly if you're not using the UI plugin, and write : window.location = $(this).attr('href');

嗼ふ静 2024-12-21 03:07:55

您可以通过以下方式选择当前节点:

$('#' + data.node.id)

代码变为:

$('#Tree').bind('loaded.jstree', function(event, data){
console.log($('#' + data.node.id)); //This is current node, see on console
}).jstree();

you can select current node by :

$('#' + data.node.id)

Code becomes:

$('#Tree').bind('loaded.jstree', function(event, data){
console.log($('#' + data.node.id)); //This is current node, see on console
}).jstree();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文