admin管理员组文章数量:1393380
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
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
Share Improve this question asked Nov 7, 2011 at 13:34 Yair NevetYair Nevet 13k17 gold badges69 silver badges109 bronze badges 2- 2 You don't want to use the 'select_node.jstree' event to do it ? – Guillaume Cisco Commented Nov 7, 2011 at 13:41
- Hi, do you have any reference or code example? – Yair Nevet Commented Nov 7, 2011 at 13:48
2 Answers
Reset to default 2Seems according to the documentation of the demo here :
http://www.jstree./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');
you can select current node by :
$('#' + data.node.id)
Code bees:
$('#Tree').bind('loaded.jstree', function(event, data){
console.log($('#' + data.node.id)); //This is current node, see on console
}).jstree();
本文标签: javascriptjsTreeGet the selected node on loadedjstree eventStack Overflow
版权声明:本文标题:javascript - jsTree - Get the selected node on loaded.jstree event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744619921a2615960.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论