我是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(),但我似乎从来没有在商店中获得任何元素。
我错过了什么?
由于 奥里奥尔
答案 0 :(得分:1)
我所理解的是,当您访问它时,您的商店数据可能尚未加载。所以把你的每个()函数放在这里来延迟500ms:
Ext.Function.defer(function(){
// Put each() here
}, 500);
尝试或多或少地推迟。