vakata/jstree — Issue #166: html_data progressive render
Author: ntenisOT
Created: 2012-02-03 21:47:25+00:00
State: open

I want to create a link like the following:

ROOT
+ Folder A
- Folder A1
- Folder A2
- Folder A3
+ Folder B
- Folder B1
- Folder B2
+ Folder C
- Folder c1

I populate the tree using `html_data` and I want to open only the root elements when the tree is loaded and then request the children of each root element when the Open event is triggered.

For example the tree should have the following format at first:

ROOT
+ Folder A
+ Folder B
+ Folder C

When the `+` next to `Folder A` is clicked the server will perform an Ajax Request in order to get and present the Folder A's children. While waiting for the result the server will display a loading icon.

The only example that I was able to find was the following:

"html_data" : {
"correct_state" : true,
"ajax" : {
"url" : function (n) {
var url;
if (n==-1)
url = "?request=tree";
else
url = "" + n.attr("idpath");
return url;
} ,
"success": function (d, t, x) {
d=d.replace(/^\s*|\s(?=\s)|\s*$/g, "");
if (d.length==0) {d=null;}
return d;
},
"error" : function (n) {
alert ("error");
}
}
},

Also jsTree's developer states in their Google Group:

Hi,

Using the latest commit (I am not sure if this is present in rc2), you can set the ajax.url config option to a function - like so:
url : function (node) { return "some/url"; }
and 'node' is the jquery extended LI node that is being loaded - this should fix all your troubles.

Can someone try to provide a more detailed example or comment the example that I found?