2017-01-04 4 views
1

프로그래밍 방식으로 이미 초기화 된 TreeStore에 데이터를 추가하는 방법을 이해하는 데 어려움을 겪고 있습니다. 난 단지 4 부모 항목이 추가 얻을 결과Sencha Touch 2.4 : 프로그래밍 방식으로 TreeStore에 여러 레코드를 추가하는 방법

var data = { 
     "items" : [{ 
      "text" : "Today", 
      "items" : [{ 
         "text" : "Eat", 
         "leaf" : true 
        }, { 
         "text" : "Sleep", 
         "leaf" : true 
        }, { 
         "text" : "Drinking", 
         "leaf" : true 
        }] 
     }, { 
      "text" : "Tomorrow", 
      "items" : [{ 
         "text" : "Watch TV", 
         "leaf" : true 
        }, { 
         "text" : "Watch Video", 
         "leaf" : true 
        }] 
     }, { 
      "text" : "This week", 
      "items" : [{ 
         "text" : "Shopping", 
         "leaf" : true 
        }] 
     }, { 
      "text" : "Later", 
      "items" : [{ 
         "text" : "Eat", 
         "leaf" : true 
        }, { 
         "text" : "Sleep", 
         "leaf" : true 
        }, { 
         "text" : "Drinking", 
         "leaf" : true 
        }] 
     }] 
    }; 

    Ext.define('Task', { 
     extend: 'Ext.data.Model', 
     config: { 
      fields: [{ 
       name: 'text', 
       type: 'string' 
      }] 
     } 
    }); 

    var store = Ext.create('Ext.data.TreeStore', { 
     model: 'Task', 
     defaultRootProperty: 'items', 
     //root: data 
    }); 

    store.addData(data.items); // I need to add data here 

    console.log(store.getAllCount()) // prints 4 but should be 13 

:

는 센차 터치 문서의 예를 생각해 보자. 아이가 추가되지 않습니다.

미리 감사드립니다.

+0

대신 당신이 defaultRootProperty을 알 더주의 깊게 내 코드를 살펴있는 경우' –

답변

0

트리의 첫 번째 레벨 만 추가합니다. ExtJS는 어린이을 찾고 내부적으로 나무를 만듭니다.

변경 모든 JSON에서 children하여 items :

var data = { 
     "items" : [{ 
      "text" : "Today", 
      "children" : [{     // <<== HERE 
         "text" : "Eat", 
         "leaf" : true 
        }, { 
         "text" : "Sleep", 
         "leaf" : true 
        }, { 
         "text" : "Drinking", 
         "leaf" : true 
        }] 
     }, { 
      "text" : "Tomorrow", 
      "children" : [{    // <<== AND HERE 

      // etc, ... 
+0

을 items'의 children''과 시도 '항목을'한다 아이의 프로퍼티의 네이밍을 처리합니다. 저장소 초기화 (루트 : 데이터 주석 처리 해제)에 항목이 추가 되더라도 솔루션이 작동하지 않습니다. 그렇지 않으면 완벽하게 작동합니다. – terreb

관련 문제