【问题标题】:How to access the elements in a sencha touch 2 store如何访问 sencha touch 2 商店中的元素
【发布时间】:2013-10-19 20:48:32
【问题描述】:

我是 Sencha Touch 的新手,所以我还在为商店的使用而苦恼。

我已经创建了这个商店,我成功地使用它来填充列表:

Ext.define('EventApp.store.events',{ 
        extend: 'Ext.data.Store',

        config: {
            model: 'EventApp.model.event',
            autoLoad: true,
            storeId: 'events',
            proxy:{
                type:'ajax',
                url: './resources/EventData.json',
                reader: {
                    type: 'json',
                    rootProperty: 'events'
                }
            }

            }

});

正如我提到的,当从列表中引用时,这家商店可以正常工作,我可以显示它的内容。因此我假设商店的定义是正确的。

不幸的是,当我尝试从控制器访问商店以获取我的一个视图(将用于填充轮播项目)时,我似乎没有从商店获取任何数据。我使用的代码如下:

onEventCarouselInitialize : function(compon, eOptions) {
    var past = compon.getPast();
    var eventsStore = Ext.getStore('events');
    eventsStore.each(function(record){
        console.log('Record =',record); //<-- this never gets executed.
    },this);
}

我尝试在 eventsStore.sync() 上执行 eventsStore.load(),但我似乎从未在商店中获得任何可用元素。

我错过了什么?

谢谢 黄鹂

【问题讨论】:

    标签: sencha-touch-2 store


    【解决方案1】:

    我的理解是,当您访问它时,您的商店数据可能尚未加载。所以把你的 each() 函数放在这个里面,用于延迟 500 毫秒:

    Ext.Function.defer(function(){
        // Put each() here
    }, 500);
    

    或多或少地延迟一下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-17
      • 2014-01-25
      • 2013-04-16
      • 2012-05-29
      • 2013-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多