【发布时间】:2014-09-30 19:04:39
【问题描述】:
在我的服务器中,我返回一个 jsTree 格式的 JSON 对象:
{"id":"value", "text":"value", "parent":"value"}
我通过 Ajax 调用将其显示在我的视野中。 Console.log 向我展示了详细信息,但 jsTree 给了我错误:
未捕获的类型错误:无法读取未定义的属性 'children'
查看:
$.ajax({
url: "/category",
dataType: 'json',
type: 'GET',
success: function (res) {
$.each(res, function (i, obj) {
products.push([obj.id, obj.parent, obj.text]);
$('#jstree_demo_div').jstree({
'core': {
'data': [{ "id": obj.id, "parent": obj.parent != 0 ? obj.parent : "#", "text": obj.text }]
}
});
console.log(obj.parent != 0 ? obj.parent : "#");
});
}
});
【问题讨论】:
-
您的页面上是否有 ID 为
jstree_demo_div的元素?用它添加 html 标记。
标签: javascript jquery ajax jstree jstree-search