[英]load a contecxtmenu from json's file using a JQuery.getJSON()
我需要從json的文件加載jsTree的contextmenu。 contextmenu保存在此文件(“test.json”)中:
{
"item1" : {
"label" : "voce1"
},
"item2" : {
"label" : "voce2"
}
}
並且加載contextmenu的代碼是:
$(function () {
$("#tree").jstree({
"plugins" : [ "themes", "json_data", "ui", "contextmenu" ],
// other code ....
"contextmenu" : {
"items" : customMenu
}
})
});
function customMenu(node) {
$.getJSON( "test.json", function(json) {
return json;
});
}
這樣,我看不到上下文菜單。 你能幫助我嗎?
我不知道jstree插件是如何工作的,但也許你應該嘗試不同的方法,首先加載發出Ajax請求的JSON數據,當它完成時,初始化jstree:
$(function () {
$.getJSON( "test.json", function(json) {
$("#tree").jstree({
"plugins" : [ "themes", "json_data", "ui", "contextmenu" ],
"contextmenu" : {
"items" : json
}
});
});
});
這是因為Ajax調用是異步的,因此您的customMenu()
函數不會向"contextmenu"
"items"
選項返回任何內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.