I need to load a jsTree’s contextmenu from a json’s file. The contextmenu is saved in this this file (“test.json”):
{
"item1" : {
"label" : "voce1"
},
"item2" : {
"label" : "voce2"
}
}
and the code to load the contextmenu is:
$(function () {
$("#tree").jstree({
"plugins" : [ "themes", "json_data", "ui", "contextmenu" ],
// other code ....
"contextmenu" : {
"items" : customMenu
}
})
});
function customMenu(node) {
$.getJSON( "test.json", function(json) {
return json;
});
}
In this way, I don’t see the contextmenu. Can you help me?
I don’t know how jstree plugin works, but maybe you should try a different approach, loading first the JSON data making the Ajax request, and when it’s finished, initialize the jstree:
This is because Ajax calls are asynchronous, so your
customMenu()function is not returning anything to your"items"option of"contextmenu".