On my server, I return a JSON object in jsTree format:
{"id":"value", "text":"value", "parent":"value"}
I get this in my opinion through an Ajax call. Console.logshows me the details, but jsTree gives me an error:
Uncaught TypeError: Unable to read the 'children' property from undefined
View:
$.ajax({
url: "/category",
dataType: 'json',
type: 'GET',
success: function (res) {
$.each(res, function (i, obj) {
products.push([obj.id, obj.parent, obj.text]);
$('#jstree_demo_div').jstree({
'core': {
'data': [{ "id": obj.id, "parent": obj.parent != 0 ? obj.parent : "#", "text": obj.text }]
}
});
console.log(obj.parent != 0 ? obj.parent : "#");
});
}
});
source
share