I had a similar problem a couple of weeks ago. I had a function call in the "url" field, which ultimately led to java code that made a JSON string based on a SQL query. So when I clicked on a childless closed node, the function was called again, resulting in an endless tree.
the way I solved this was:
"json_data" : {
"ajax" : {
"url" : "getAreaTree?treeType=Areas&ownerPhone=<%=webSessionObject.getUserPhoneNum()%>",
"data" : function (n) {
return { id : n.attr ? n.attr("id") : 0 };
}
}
},
The result of the function defined in "data" will be added as a parameter to the "url" function. Then I can check whether the parameter was 0 (initial load) or 1 (the id of my root) or something else.
If this doesn't work for you, maybe you could try something like this:
.bind("before.jstree",function(event,data){
if(data.func === "create"){
var foo = true;
data.inst._get_node(null, true).each(function () {
if(this.id!=rootId && this.id!=0){
foo = false;
})
if(!foo){
event.stopImmediatePropagation();
return false;
}
}
})
I'm not exactly sure this works though. "before.jstree" fires before all events. I'm checking whether the function about to fire is "create", and if it is I check the id of the selected node. If it's something else than my root's id or 0 (initial load) I stop the create function.
I use a similar structure for a different situation, so something like this should work. It could be that the "create" event is not what you should be binding to though. You can change it to
.bind("before.jstree",function(event,data){
console.log(data.func)
if(data.func === "create"){
To see which functions are called.