Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从json';使用JQuery.getJSON()的_Javascript_Jquery_Json_Jstree - Fatal编程技术网

Javascript 从json';使用JQuery.getJSON()的

Javascript 从json';使用JQuery.getJSON()的,javascript,jquery,json,jstree,Javascript,Jquery,Json,Jstree,我需要从json文件加载jsTree的contextmenu。contextmenu保存在此文件(“test.json”)中: 加载contextmenu的代码是: $(function () { $("#tree").jstree({ "plugins" : [ "themes", "json_data", "ui", "contextmenu" ], // other code .... "contextmenu" : {

我需要从json文件加载jsTree的contextmenu。contextmenu保存在此文件(“test.json”)中:

加载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插件是如何工作的,但也许你应该尝试另一种方法,首先加载JSON数据,发出Ajax请求,完成后,初始化jstree:

$(function () {
 $.getJSON( "test.json", function(json) {
  $("#tree").jstree({ 
    "plugins" : [ "themes", "json_data", "ui", "contextmenu" ],
    "contextmenu" : {
      "items" : json
    }
  });
 });
});

这是因为Ajax调用是异步的,所以您的
customMenu()
函数没有向
“contextmenu”
“items”
选项返回任何内容。Ajax调用不是异步的还是同步的?
$(function () {
 $.getJSON( "test.json", function(json) {
  $("#tree").jstree({ 
    "plugins" : [ "themes", "json_data", "ui", "contextmenu" ],
    "contextmenu" : {
      "items" : json
    }
  });
 });
});