jortiz81
jortiz81

Reputation: 559

Set node attributes on node in jstree

When I load the tree I load it using the following snippet:

{"data":"admin","state":"closed","metadata":{"id":"\/admin\/","type":"default"}

When I grab a referenced to a particular chosen node I use:

jQuery.data(data.rslt.obj[0], "jstree").id;

However, when I add a new node, i'm not sure how to set the id of the new node. I've seen some examples that say to use the following:

var newnode = data.rslt.obj;
newnode.attr("id", new_node_id);

Where new_node_id is generated by me, but this doesn't seem to work. Can someone help?

Upvotes: 4

Views: 10440

Answers (2)

mikewasmike
mikewasmike

Reputation: 388

If you are using json data to populate your tree, then you should supply it in the json string: see the docu

Upvotes: 0

nicohvi
nicohvi

Reputation: 2270

I just use the provided method from the CRRM documentation:

$("#treeContainer").jstree("create", parentNode, "position", {attr: {id: your_generated_id ...}, data: "nodeTitle"} ,null, true);

Works like a charm for me.

Upvotes: 1

Related Questions