【问题标题】:jstree dynamic JSON data from django来自 django 的 jstree 动态 JSON 数据
【发布时间】:2011-03-04 05:54:57
【问题描述】:

我正在尝试设置 jsTree 以动态接受来自 django 的 JSON 数据。

这是我让 django 返回到 jstree 的测试数据:

result=[{ "data" : "A node", "children" : [ { "data" : "Only child", "state" : "closed" } ], "state" : "open" },"Ajax node"]
response=HttpResponse(content=result,mimetype="application/json")

这是我正在使用的 jstree 代码:

jQuery("#demo1").jstree({   
           "json_data" : {  
             "ajax" : {  
                "url" : "/dirlist",  
                "data" : function (n) {   
                    return { id : n.attr ? n.attr("id") : 0 };   
                },
                 error: function(e){alert(e);}
             }  
         },  
        "plugins" : [ "themes","json_data"]
     });

我得到的只是 ajax 加载符号,ajax 错误响应也被触发并且它警告“未定义”。我也在 django 中尝试过 simpleJson 编码,但结果相同。

如果我更改 url 以便它接收具有相同数据的 JSON 文件,它会按预期工作。

关于问题可能是什么的任何想法?

【问题讨论】:

    标签: jquery django json jstree


    【解决方案1】:

    似乎问题是我在包含应用程序/JSON mimetype 时没有同时进行 simplejson 编码。

    全部排序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-02
      • 2018-05-12
      • 1970-01-01
      • 1970-01-01
      • 2012-04-11
      • 2010-11-22
      相关资源
      最近更新 更多