2014-07-15 2 views
0

Laravel 4fancytree을 사용하고 있습니다.Fancytree가 특정 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": [] 
      }] 
     }] 
    }] 
} 

내가 fancytree에 요소 survey_dataJSON을로드 할 :

나는 JSON 데이터 뭔가 같이 돌려 주어 api 전화를 가지고있다.

현재, 내 코드는 다음과 같은 것입니다 : 변수 sourceURL에서

var tree = function (treeDiv,sourceURL){ 
    treeDiv.fancytree({ 
     source : sourceURL 
    }) 
} 

내가 통과하고있는 api url와 내가 올바른 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의 최신 버전을 사용하고 있습니다 있습니다.

아무도 도와 줄 수 있습니까?

감사합니다.

답변

2

그것을 자신을 해결 : 나는 게으른 로딩이 작업을 수행 할 방법

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

    postProcess: function(event, data) { 
     data.result = $.parseJSON(data.response.survey_data); 
    } 
}] 
+0

어떤 생각? 게으른로드 중일 때 postProcess 함수가 호출되지 않습니다. – Displee

관련 문제