This is a simple example - you could enhance it not to pollute the global namespace.
01.
var
stat = [
02.
{
"attributes"
: {
"id"
:
"node_1"
},
"data"
:
"Node 1"
},
03.
{
"attributes"
: {
"id"
:
"node_2"
},
"data"
:
"Node 2"
,
"state"
:
"closed"
},
04.
{
"attributes"
: {
"id"
:
"node_3"
},
"data"
:
"Node 3"
}
05.
];
06.
$(
function
() {
07.
$(
"#sa_json_1"
).tree({
08.
data : {
09.
type :
"json"
,
10.
async :
true
,
11.
opts : {
12.
method :
"POST"
,
13.
url :
"async_json_data.json"
14.
}
15.
},
16.
callback : {
17.
// Take care of refresh calls - n will be false only when the whole tree is refreshed or loaded of the first time
18.
// Make sure static is not used once the tree has loaded for the first time
19.
beforedata :
function
(n, t) {
20.
if
(n ==
false
) t.settings.data.opts.staticData = stat;
21.
else
t.settings.data.opts.staticData =
false
;
22.
}
23.
}
24.
});
25.
});