0
votes

I'm trying to figure out when a store is ready to be used within my app. I figured from the doc that if I want to display information from my store, I should listen to the 'refresh' event of my store to get notified when it has been changed (and thus also when it is first loaded).

However, using the following example:

Ext.define('MyApp.store.Config', {  
extend: 'Ext.data.Store',
config: {
    autoLoad: true,
    autoSync: true,
    model: 'MyApp.model.Config',        
    listeners: {
        refresh: function() {
            console.log(Ext.StoreManager.get('Config').getAt(0))
        }
    }
} });

the 'console.log' gets called twice at startup, and it fails the first time (it seems that the Store is not loaded yet). My model uses a proxy (type ajax, and a json reader).

Could someone tell me how I should proceed to avoid this error? Thanks!

1
Is there a reason you cannot use the load event? - rdougan
@rdougan The same problem is happening when I use load. I was using refresh because in the doc, they mention that one shouldn't use load for ui refresh purpose... - borck
refresh should be used when updating the UI, because it also gets called when a single record is added/updated/deleted. But it looks like you want to know the first time the store has loaded, so using load makes more sense. - rdougan
@rdougan right, I agree but nevertheless, the problem that I mention happens in both cases... Any idea why? This doesn't happen for my other stores using localstorage... Might be related to Ajax loading? For info, in this case the file loaded by the proxy is on the client side.... - borck

1 Answers

0
votes

I found the reason...

I was declaring the 'stores:['Config']' property both in my app.js and in on of my controllers.

Quite hard to spot but my mistake...