use*_*482 5 javascript ajax jquery jstree jstree-search
在我的服务器中,我以jsTree的格式返回JSON对象:
{"id":"value", "text":"value", "parent":"value"}
Run Code Online (Sandbox Code Playgroud)
我通过Ajax调用获得了它。Console.log
向我显示了详细信息,但是jsTree给了我错误:
未捕获的TypeError:无法读取未定义的属性“子级”
视图:
$.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 : "#");
});
}
});
Run Code Online (Sandbox Code Playgroud)
use*_*482 -1
我正在使用 Ajax 。
我通过声明一个包含(id,parent,text)的新对象javaScript解决了这个问题
例子:
var objJS = new Object();
objJS .id = ObjectJason.id;
objJS .parent = ObjectJason.parent!=="0" ? ObjectJason.parent:"#";
objJS .text = ObjectJason.text;
Run Code Online (Sandbox Code Playgroud)
我声明一个数组,在其中推送所有对象并将其赋予“数据”,如下所示
$('#jstree_demo_div').jstree({
'core': {
'data': Array ;
}
});
Run Code Online (Sandbox Code Playgroud)
并且运行完美!我希望它能帮助很多人
归档时间: |
|
查看次数: |
7563 次 |
最近记录: |