I'm new to jqTree. I am trying to use the function: getSelectedNode found here: jqTree functions I have my tree working and being displayed using my own data as well as the sample data within this function:
$(function() { $('#tree1').tree({ data: data, dragAndDrop: true, autoOpen: 1 }); });Using the jqTree function below, I only ever get "null" out on loading the page. Furthermore nothing changes when I select a node.
var node = $('#tree1').tree('getSelectedNode'); console.log(node);I have also tried the given sample:
var node = $tree.tree('getSelectedNode'); console.log(node);In this case I get $tree not defined
Essentially, what am I doing wrong? How does these type of jqTree functions work? Tks !
1 Answer
It appears that you have to wrap this function in a click event. But of course, the docs don't tell you that. I found the source here: jqTree I htis helps someone else.
$('#tree1').bind(
'tree.click',
function(event) { // The clicked node is 'event.node' var node = event.node; alert(node.name);
});