2012-03-04 56 views
2

我是Sencha Touch和網絡編程的新手。我試圖顯示一個嵌套列表,並且只是一次又一次地獲取循環中的第一級項目。我已經看過文檔和廚房水槽的例子,但我無法正確理解它。我會非常感謝提示!嵌套列表與Sencha Touch無限循環1

這是我的代碼:

Ext.regModel('Site', { 
fields: [ 
    {name: "sitename", type: "string"}, 
    {name: "last_connection", type: 'auto'}, 
] 

}); 


Ext.setup({ 
icon: 'icon.png', 
tabletStartupScreen: 'tablet_startup.png', 
phoneStartupScreen: 'phone_startup.png', 
glossOnIcon: false, 
onReady: function(){ 

    var store = new Ext.data.TreeStore({ 
     model: 'Site', 
     proxy: { 
      type: 'ajax', 

      url: 'network.json', 
      reader: { 

       type: 'json', 
       root: 'items' 

      } 
     } 
    }); 


    var nestedList = new Ext.NestedList({ 
     fullscreen: true, 
     title: 'Netzwerk', 
     displayField: 'sitename', 
     plugins: [new Ext.LeafSelectedPlugin()], 
     // add a/for folder nodes in title/back button 
     getTitleTextTpl: function() { 
      return '{' + this.displayField + '}<tpl if="leaf !== true">/</tpl>'; 
     }, 
     // add a/for folder nodes in the list 
     getItemTextTpl: function() { 
      return '{' + this.displayField + '}<tpl if="leaf !== true">/</tpl>'; 
     }, 

     store: store 
    }); 

} 
}); 

而且JSON文件的結構(只有一個節點爲例):

{"items": [{ 
"id":"11", 
"sitename":"Site A", 
"items":[ 
    { 
    "id":"11", 
    "sitename":"Endpoint 1", 
    "last_connection":"2012-03-02T10:03:22+0100", 
    "ping_time":63, 
    "leaf": true 
    }, 
    { 
    "id":"12", 
    "sitename":"Endpoint 2", 
    "last_connection":"2012-03-02T10:03:22+0100", 
    "ping_time":57, 
    "leaf": true 
    }], 
"last_connection":"2012-03-02T10:03:22+0100", 
"ping_time":57 

}]} 

謝謝!

回答

0

我知道這個帖子是有點老了,但如果將已經回答了這個問題就會有救了我2我生命中的「長」時間,所以這裏有雲:

我想通了,我失蹤TreeStore裏面的defaultRootProperty。根據您的JSON,您需要將此屬性設置爲items

這裏是如何您TreeStore應該是這樣的:

var store = new Ext.data.TreeStore({ 
    model: 'Site', 
    defaultRootProperty: 'items', 
    proxy: { 
     type: 'ajax', 
     url: 'network.json', 
     reader: { 
      type: 'json', 
      root: 'items' 
     } 
    } 
});