使用Sencha Touch 1的嵌套列表无限循环

时间:2012-03-04 15:21:21

标签: sencha-touch nested-lists

我是Sencha Touch和网络编程的新手。我试图显示一个嵌套列表,我只是一遍又一遍地获取循环中的第一级项目。

我已经看过文档和厨房水槽示例,但我无法做到正确。我会非常感谢提示!

这是我的代码:

 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
    }]
}

谢谢!

1 个答案:

答案 0 :(得分:0)

我知道这篇文章有点陈旧,但如果它已经得到回答,它将为我节省2个“长”的生命时间,所以这就是:

我发现我错过了defaultRootProperty内的TreeStore。根据您的JSON,您需要将此属性设置为items

以下是TreeStore的外观:

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