Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
165
rated 0 times [  169] [ 4]  / answers: 1 / hits: 59736  / 11 Years ago, mon, november 18, 2013, 12:00:00

I am trying to get the selected Node from a jstree.



This is the code in the View



<div id=divtree >
<ul id=tree >
@foreach (var m in Model.presidentList)
{
<li class=jstree-clicked>
<a href=# class=usr>@m.Name</a>
@Html.Partial(Childrens, m)
</li>
}
</ul>
</div>


This is the javascript part where I try to retrieve the name of the Node



$(.jstree-clicked).click(function (e) {
var node = $(this).jstree('get_selected').text();
alert(node);
});


I have a problem on getting only the selected node. If I select one of the children(last node of the tree for example) I still get the entire list of nodes. Please let me know if you have any idea where I am doing something wrong?


More From » jquery

 Answers
1

I don't think you should assign class 'jstree-clicked' for each <li> node.
And get selected node using jstree container that you used for jstree binding.



console.log($(#divtree).jstree(get_selected).text());

[#74219] Saturday, November 16, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leog

Total Points: 225
Total Questions: 113
Total Answers: 118

Location: Oman
Member since Wed, Apr 12, 2023
1 Year ago
;