How to create a new identifier for a newly added node?

Usually I can get the identifier of the tree nodes by default, but my problem is onCreate, then jsTree will add a new node, but it has no identifier. My question is: how to add an identifier to a newly created node tree?

What I'm going to do is add the HTML ID attribute to the newly created node tree, but how?

I need to get the identifier of all nodes, because it will serve as a reference for the corresponding div node 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

+3
source share
1 answer

If you have access to node, you can add it yourself:

$(NODE).attr('id',id_value);
+3
source

Source: https://habr.com/ru/post/1746323/


All Articles