views:

65

answers:

1

Hi,

I can normally get the ID of the default tree nodes but my problem is onCreate then jsTree will add a new node but it doesn't have an ID. My question is how can I add an ID to the newly created tree node?

What I'm thinking to do is adding the ID HTML attribute to the newly created tree node but how?

I need to get the ID of all of the nodes because it will serve as a reference for the node's respective div storage.

HTML code:

<div class="demo" id="demo_1">
<ul>
    <li id="phtml_1" class="file"><a href="#"><ins>&nbsp;</ins>Root node 1</a></li>
    <li id="phtml_2" class="file"><a href="#"><ins>&nbsp;</ins>Root node 2</a></li>
</ul>
</div>

JS code:

$("#demo_1").tree({
    ui : {
        theme_name : "apple"
    },
    callback : {
        onrename : function (NODE, TREE_OBJ) {
            alert(TREE_OBJ.get_text(NODE));
            alert($(NODE).attr('id'));
        }
    }
});

Cheers, Mark

+2  A: 

If you have access to the node you should be able to add the ID by yourself:

$(NODE).attr('id',id_value);
Andris
Thanks but I just found out that what about the copy paste functionality of the jsTree? It will then duplicate the ID of the pasted nodes. But I think I will have to remove that functionality to make it simple.I will just add a hidden field to store the last ID of a tree node so that when I create a new node then I will get the last ID and increment it.
marknt15