The built in JSON datastore lets you define some static data to use to build the tree. Those two examples show a few basics of the JSON datastore format.
01.
$(
function
() {
02.
$(
"#basic_json_1"
).tree({
03.
data : {
04.
type :
"json"
,
05.
opts : {
06.
static : [
07.
{
08.
// the short format demo
09.
data :
"A node"
,
10.
// here are the children
11.
children : [
12.
{ data :
"Child node 1"
},
13.
{ data :
"Child node 2"
},
14.
{ data :
"Child node 3"
}
15.
]
16.
},
17.
{
18.
attributes : {
"id"
:
"li.node.id"
},
19.
// this is the long data format
20.
data : {
21.
title :
"Long format demo"
,
22.
attributes : {
"href"
:
"http://jstree.com"
}
23.
}
24.
}
25.
]
26.
}
27.
}
28.
});
29.
});
You can also force a node in a closed or open state (notice in the previous example, that the node having children is intially closed).
01.
$(
function
() {
02.
$(
"#basic_json_2"
).tree({
03.
data : {
04.
type :
"json"
,
05.
opts : {
06.
static : [
07.
{ data :
"A node"
, children : [ { data :
"Only child"
} ],
08.
// this node will initially be open
09.
state :
"open"
10.
},
11.
{ data :
"Some other node"
,
12.
// this node will appear closed even though it has no children
13.
state :
"closed"
14.
}
15.
]
16.
}
17.
}
18.
});
19.
});