Using jsTree, I get data.rslt undefined when trying to read the data object.
Here is my jQuery, creating a tree, loading the JSON and it should output the data.rslt object to the console when loaded.
$(function () {
$("#demo1").jstree({
"plugins" : [ "themes","json_data","ui", "crrm" ],
"json_data" : {
"ajax" : {
"url" : "categorytreejson.asp"
}
},
"ui" : {
"initially_select" : [ "root" ]
}
});
$("#demo1").bind("loaded.jstree", function (e, data) {
console.log(data.rslt)
});
});
Here is the JSON data
{"data": "root", "attr": {"id": "root"}, "children": [{"data": "Photography", "attr": {"id": "Photography"}, "children": [{"data": "Lenses", "attr": {"id": "Lenses"}, "children": [{"data": "Telephoto", "attr": {"id": "Telephoto"}},{"data": "Macro", "attr": {"id": "Macro"}},{"data": "Other", "attr": {"id": "Other"}}]}]}]}
The resulting HTML
<li class="jstree-last jstree-open" id="root"><ins class="jstree-icon"> </ins><a class="" href="#"><ins class="jstree-icon"> </ins>root</a><ul style=""><li class="jstree-closed" id="Photography"><ins class="jstree-icon"> </ins><a class="" href="#"><ins class="jstree-icon"> </ins>Photography</a><ul><li class="jstree-last jstree-closed" id="Lenses"><ins class="jstree-icon"> </ins><a href="#"><ins class="jstree-icon"> </ins>Lenses</a><ul><li class="jstree-leaf" id="Telephoto"><ins class="jstree-icon"> </ins><a href="#"><ins class="jstree-icon"> </ins>Telephoto</a></li><li class="jstree-leaf" id="Macro"><ins class="jstree-icon"> </ins><a href="#"><ins class="jstree-icon"> </ins>Macro</a></li><li class="jstree-last jstree-leaf" id="Other"><ins class="jstree-icon"> </ins><a href="#"><ins class="jstree-icon"> </ins>Other</a></li></ul></li></ul></li></li></ul></li></ul></li>
And the data object in Firebug.
args: []
inst: Object { data={...}, get_settings=function(), _get_settings=function(), more...}
rlbk: false
rslt: undefined
Some events will not populate the
data.rsltobject.As of the jsTree core documentation:
data structure:
In particular, the
loaded.jstreeevent will have an empty data.rslt because no additional data was passed to the function.Other events like
create.jstreeorrename.jstreewill have the data.rslt populated.I hope it’s more clear to you now 🙂