0

と を使用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を取得していることを firebug で確認しました。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

誰でも私を助けることができますか?

ありがとう。

4

1 に答える 1

2

自分で解決しました:

treeDiv.fancytree({
    source: {
      url: sourceURL,
    },

    postProcess: function(event, data) {
      data.result = $.parseJSON(data.response.survey_data);
    }
}]
于 2014-07-15T13:18:39.560 に答える