cant bind select_node.jstree

2,229 views
Skip to first unread message

Mauricio Garavaglia

unread,
Oct 6, 2010, 7:11:57 PM10/6/10
to jsTree
Hi, I have a problem trying to bind the click event of the nodes. my
code is the following

tree_data = eval(<%= json_data_from_the_server %>);
$(function() {
$('#tree_container').jstree({
core : { animation : 0} ,
plugins : ['json_data', 'themes'] ,
json_data : tree_data, themes : { url: '/stylesheets/
tree.css'}
});
$('#tree_container').bind("select_node.jstree",
function(e,data) {
var node_id =data.rslt.obj.attr("id");
alert('you selected the node '+node_id);
});
});

but it doesn't work. if I use delegate('a', 'click', function(e)
{ ...}) instead of bind() it seems to work but i can't access the data
object anymore. Im using jstree1.0rc2 with jquery 1.4.2 on Firefox.
Thanx!

Mauricio

CroNiX

unread,
Oct 6, 2010, 8:20:30 PM10/6/10
to jsTree
try binding it directly like:
$('#tree_container').jstree({
core : { animation : 0} ,
plugins : ['json_data', 'themes'] ,
json_data : tree_data, themes : { url: '/stylesheets/tree.css'}
}).bind("select_node.jstree", function(e,data) {
var node_id =data.rslt.obj.attr("id");
alert('you selected the node '+node_id);
});

On Oct 6, 4:11 pm, Mauricio Garavaglia <mauriciogaravag...@gmail.com>
wrote:

stefa_n

unread,
Oct 11, 2010, 3:18:00 AM10/11/10
to jsTree
Hi,

I have the exact same problem, but binding directly didn't help.
Mauricio, were you able to solve this already?

stefa_n

unread,
Oct 9, 2010, 6:01:08 AM10/9/10
to jsTree

I have the exact same problem, but binding it directly didn't
solve it. Mauricio, did it worked in your case?

vakata

unread,
Oct 12, 2010, 5:15:48 PM10/12/10
to jsTree
Hi,
to bind to the select_node event, the select_node function should be
active on the tree (the UI plugin must be included) as for the first
post - simply add it to the plugins array: ... "themes","ui"]
And all will work.

When using delegate (not using the UI plugin):
.delegate("a", "click", function (e) {
e.target.parentNode.id // this is the ID
});

Kindest regards,
Ivan
Reply all
Reply to author
Forward
0 new messages