【发布时间】:2014-07-15 21:18:39
【问题描述】:
我正在使用Laravel 4 和fancytree。
我有一个 api 调用返回 JSON 数据,如下所示:
{
"error":false,
"survey_data":"[{
"id": 1,
"type": "group",
"subtype": null,
"title": "General ",
"parent": null,
"children": [{
"id": 30,
"type": "question",
"subtype": "boolean",
"title": "Did you..?",
"parent": 1,
"children": [{
"id": 31,
"type": "answer",
"subtype": null,
"title": "Yes",
"parent": 30,
"children": []
}]
}]
}]
}
我想将元素survey_data 的JSON 加载到fancytree 中。
目前,我的代码是这样的:
var tree = function (treeDiv,sourceURL){
treeDiv.fancytree({
source : sourceURL
})
}
在变量sourceURL 中,我传递了api url,并且我用firebug 验证了我得到了正确的JSON 数据。但是我不确定如何将这个survey_dataJSON 作为源加载。
我也试过了:
source: jQuery.ajax({
url: sourceURL,
type: 'GET',
dataType: 'json',
complete: function(xhr, textStatus) {
},
success: function(data, textStatus, xhr) {
return data.survey_data;
},
error: function(xhr, textStatus, errorThrown) {
}
})
但出现错误:
Uncaught Error: Assertion failed: source must contain (or be) an array of children
请注意,我使用的是最新版本的fancytree。
谁能帮帮我?
谢谢。
【问题讨论】:
标签: php ajax laravel-4 fancytree