2012-08-29 3 views
4

ExtJS 4.0.7 TreePanel에 문제가 있습니다. JSON 요청에서 전체 트리를로드하고 싶습니다. 요청은 다음과 같은 반환ExtJS 4.0.7로드 완료 TreePanel

: (또는 다른 내가 해봤)

Ext.define('My.store.SysInfo', { 
extend: 'Ext.data.TreeStore', 
    model: 'My.model.SysInfo', 

    proxy : { 
     type : 'ajax', 
     url : '/sysinfo/getSysInfo.php', 
     reader : { 
      root : 'data' 
     } 
    } 
}); 

모델 다음 저장소 구성에서 작동하지 않는 그와

{ 
    "data": { 
    "children": [ 
     { 
     "text": "OS", 
     "leaf": false, 
     "children": [ 
      { 
      "text": "Hostname", 
      "leaf": false, 
      "children": [ 
       { 
       "text": "hostname.int.com", 
       "leaf": true, 
       "children": [] 
       } 
      ] 
      } 
     ] 
     } 
    ] 
    } 
} 

을 다음과 같은 코드가 있습니다 이 구성에 treepanel을 추가 할 때

Ext.define('My.model.SysInfo', { 
    extend: 'Ext.data.Model', 
    fields: ['text'] 
}); 

, 그것은 작동하지 않습니다 :

{ 
    xtype: 'treepanel', 
    name : 'sysinfo', 
    height: '100%', 
    store: 'My.store.SysInfo', 
    lines: true, 
    autoScroll : true, 
    expanded : true, 
    rootVisible: false, 
    folderSort: true, 
    multiSelect: false, 
    useArrows: true, 
} 

노드를 열면 ExtJS는 항상 미리로드 된 데이터를 표시하는 대신 ajax를 통해 루트 노드에서 전체 노드를 요청하여 하위 노드로 전체 트리를로드합니다. 어떻게하면 "OS"를 열어 "호스트 이름"노드를로드 할 수 있습니까?

+1

어쨌든, 좋은 질문을 – sra

답변

6

확실히 할 수 있습니다. 하지만 당신의 아들에게는 문제가있는 것 같습니다.

json의 루트는 data이지만 중첩 된 데이터를 올바르게로드하려면 루트 및 모든 하위 속성이 동일해야합니다. 독자의 루트를 data으로 정의 했으므로 json의 children을 모두 data으로 바꿔야합니다.

this question에서 확인하십시오. 자세한 내용은 this question을 참조하십시오. 이을 살펴볼 수도 있습니다.

당신과 같이 당신의 독자를 정의하는 경우 :

reader : { 
     type: 'json', 
     // root : 'children' // no real need for this a children is the default. 
    } 

이 JSON가 제대로로드해야합니다

{ 
    "children":[ 
    { 
     "text":"OS", 
     "leaf":false, 
     "children":[ 
      { 
       "text":"Hostname", 
       "leaf":false, 
       "children":[ 
       { 
        "text":"hostname.int.com", 
        "leaf":true, 
        "children":[ 

        ] 
       } 
       ] 
      } 
     ] 
    } 
    ] 
} 
관련 문제