我正在尝试设置 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 文件,它会按预期工作。
关于问题可能是什么的任何想法?