【问题标题】:I load the store/model but the list is emty in Sencha Touch我加载了商店/模型,但 Sencha Touch 中的列表为空
【发布时间】:2015-11-17 15:13:48
【问题描述】:

我加载了一个数据,它来自一个 rest API:

Ext.ModelManager.getModel('Test.model.DogDetails').load(12);

是的,它已加载。我可以在网络事件中看到api.example.com/dogdetails/12。它有一只狗(“数组”)。

我有一个容器内的列表:

Ext.define('Test.view.DogDetails', {
    extend: 'Ext.Container',
    xtype: 'DogDetails',
    //singleton: true,
    config: {
        layout: 'fit',
        items : [
            {
                xtype: 'list',
                store: 'DogDetails',
                itemTpl: [
                    '{NAME}'
                ],
                variableHeights: true
            }
        ]
    }
});

然后,我点击一个按钮弹出视图。

this.dogD = Ext.widget('DogDetails', {
    title: "hghgh"
});
Ext.ComponentQuery.query('dogNavigationView')[0].push(this.dogD);

而且列表是空的。我检查了列表的商店,它说商店从未加载过。所以,这似乎不是如何加载数据的方式。但是后来我尝试Test.view.DogDetails.items.items[0].getStore().getModel().load(12); 这个加载了我想要的商店,但它没有加载api.example.com/dogdetails/12,它加载了api.example.com/dogdetails/,它是空的。我也试过用singelton,但是Test.view.DogDetails.items.items[0]不存在。

用商店弹出列表的正确方法是什么?

【问题讨论】:

  • 很可能你错误​​地定义了你的模型/代理。把它的定义和内容放在 api.example.com/dogdetails/12

标签: javascript extjs sencha-touch sencha-touch-2 store


【解决方案1】:

下面是一个显示商店列表的示例:

Ext.define('Contact', {
    extend: 'Ext.data.Model',
    config: {
        fields: ['firstName', 'lastName']
    }
});

var store = Ext.create('Ext.data.Store', {
   model: 'Contact',
   sorters: 'lastName',

   grouper: {
       groupFn: function(record) {
           return record.get('lastName')[0];
       }
   },

   data: [
       { firstName: 'Tommy',   lastName: 'Maintz'  },
       { firstName: 'Rob',     lastName: 'Dougan'  },
       { firstName: 'Ed',      lastName: 'Spencer' },
       { firstName: 'Jamie',   lastName: 'Avins'   },
       { firstName: 'Aaron',   lastName: 'Conran'  },
       { firstName: 'Dave',    lastName: 'Kaneda'  },
       { firstName: 'Jacky',   lastName: 'Nguyen'  },
       { firstName: 'Abraham', lastName: 'Elias'   },
       { firstName: 'Jay',     lastName: 'Robinson'},
       { firstName: 'Nigel',   lastName: 'White'   },
       { firstName: 'Don',     lastName: 'Griffin' },
       { firstName: 'Nico',    lastName: 'Ferrero' },
       { firstName: 'Jason',   lastName: 'Johnston'}
   ]
});

Ext.create('Ext.List', {
   fullscreen: true,
   itemTpl: '<div class="contact">{firstName} <strong>{lastName}</strong></div>',
   store: store,
   grouped: true
});

如需更多了解,请查看docs

【讨论】:

    猜你喜欢
    • 2012-06-17
    • 1970-01-01
    • 2011-09-01
    • 2014-02-21
    • 2012-05-29
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    • 2015-04-05
    相关资源
    最近更新 更多