Stumped on JS Tree... how to get the ID of currently selected <LI>?
I wish JStree had more examples of peforming AJAX actions when deleting a node, etc. Like how does it transfer the ID of selected node and pass that as a parameter? Spent a few hours and can't figure this 开发者_Go百科one out.
<li id="10" class="open"><a style="" class="clicked" href="#"><ins> </ins>fff</a> </li>
<li id="1" class="open"><a href="#"><ins> </ins>111</a> </li>
<li id="2" class="open"><a href="#"><ins> </ins>aaa</a> <ul>
<li id="3" class="open"><a href="#"><ins> </ins>Wonderful</a> <ul>
<li id="9" class="open last"><a href="#"><ins> </ins>bbb</a>
</li>
</ul>
So if I do something like a rename, how do I get the ID in the LI tag of selected node like the node_id?
$("#tree2").tree({
callback : {
onrename : function (NODE, TREE_OBJ) {
alert(node_id);
}
} });
Any help appreciated!
The plugin passes you the node involved; have you tried simply
alert($(NODE).attr('id'));
?
You should use node.id instead.
I was struggling for same and found a simplest way as below for key and value:
alert(node.id + ' ' + node.text);
Full Example Below:
HTML Code (have to assign id
for each li
either parent or child element):
<li id="<?php echo $result['FILTER_ID']; ?>">
Complete JS Code below:
var nodes = $('#tt').tree('getChecked');
var s = '';
for(var i=0; i<nodes.length; i++){
if (s != '') s += ',';
s += nodes[i].id + ' ' + nodes[i].text;
}
alert(s);
精彩评论