我正在使用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": []
}]
}]
}]
}
我想将JSONof 元素加载survey_data到fancytree.
目前,我的代码是这样的:
var tree = function (treeDiv,sourceURL){
treeDiv.fancytree({
source : sourceURL
})
}
在变量sourceURL中,我通过了api url并且我已经用萤火虫验证了我得到了正确的JSON数据。但是,我不确定如何将其加载survey_data JSON为源。
我也试过:
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.
有谁能够帮我?
谢谢。