Getting the id of a node object

11 views
Skip to first unread message

balance

unread,
Oct 21, 2010, 10:52:56 AM10/21/10
to jsTree
Hi,

I see in the docs and demo that you use:
var id = data.rslt.obj.attr("id");

where as I cannot get to the id unless I use find("a") to get the
anchor element, like this:
var id = data.rslt.obj.find("a").attr("id");

I use json_data, and the generated json for my tree looks like this:
[
{
"data" : {
"title" : "All",
"state" : "open",
"attr" : {
"id" : "27",
"isDefault" : "False",
"isRoot" : "True"
}
},
"children" : [
{
"data" : {
"title" : "Default",
"attr" : {
"id" : "28",
"isDefault" : "True"
}
}
}
]
}
]

Am i doing something wrong, or just missing something completely here?

vakata

unread,
Oct 29, 2010, 6:31:33 PM10/29/10
to jsTree
Take a look at the JSON documentation for the structure.
I put the IDs on the LI nodes (jstree uses those internally if
provided), so the JSON is:
{
attr : { ... }
state : "some-state", // state won't work inside the "data" object
data : "Some title" // short format
}

As mentioned - check the JSON docs for more :)

Kindest regards,
ivan

stefa_n

unread,
Nov 7, 2010, 4:17:16 AM11/7/10
to jsTree
If you have "older" JSON-data take care to switch from attributes to
attr
or it won't work either. Took me a while to find that one ;)
Reply all
Reply to author
Forward
0 new messages