English 中文(简体)
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 one out.

<li id="10" class="open"><a style="" class="clicked" href="#"><ins>&nbsp;</ins>fff</a> </li> 
<li id="1" class="open"><a href="#"><ins>&nbsp;</ins>111</a> </li> 
<li id="2" class="open"><a href="#"><ins>&nbsp;</ins>aaa</a> <ul> 
<li id="3" class="open"><a href="#"><ins>&nbsp;</ins>Wonderful</a> <ul> 
<li id="9" class="open last"><a href="#"><ins>&nbsp;</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);




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签