PDA

View Full Version : Store listener problem in controller



Cp_Barbossa
17 Sep 2012, 9:23 AM
Hello.
I have a problem on listening store events in controller.

So, my store looks like this:

Ext.define('app.store.MyTreeStore', {
extend: 'Ext.data.TreeStore',
alias: 'widget.mytreestore',
model: 'some model',
proxy: {
type: 'ajax',
url: 'some url'
}
});

And now, in my controller i'm trying to listen beforeload event:

Ext.define('app.controller.ApplicationController', {
extend: 'Ext.app.Controller',
stores: [
'app.store.MyTreeStore'
],
init: function () {
this.getStore('MyTreeStore').on('beforeload', this.onBeforeLoad, this);
},
onBeforeLoad: function () {
alert('');
}
});
So, the problem is that as soon as init function executes firebug gives me an error, seems like store tries to load data, but not according the proxy url, it posts something like this:
Get http://localhost/MyProject/scripts/app/store/MyTreeStore.js?_dc (http://wd/wd/wad/wadwd/wdwadwa/wdwadwd)=1347900348333 (http://localhost/MyProject/scripts/app/store/MyTreeStore.js?_dc=1347900348333)
I believe getStore() method creates store if not exists and maybe trying to load something? I want to prevent that. I did turn store autoLoad to false but did not help.
Do not understand what is happening.

Can someone help me? And what is the best way to listen store events in controller?

scottmartin
17 Sep 2012, 11:02 AM
You can use something like:



init : function () {
var me = this;

me.getMyStore().on({
load : me.loadMyStore
});

me.control({
// ..
});
}


Scott.

vietits
17 Sep 2012, 3:51 PM
Try to fix your code as below:


Ext.define('app.controller.ApplicationController', {
extend: 'Ext.app.Controller',
stores: [
// 'app.store.MyTreeStore'
'MyTreeStore'
],
init: function () {
this.getStore('MyTreeStore').on('beforeload', this.onBeforeLoad, this);
// this.getMyTreeStoreStore().on('beforeload', this.onBeforeLoad, this); <- You can also use this syntax
},
onBeforeLoad: function () {
alert('');
}
});

Or


Ext.define('app.controller.ApplicationController', {
extend: 'Ext.app.Controller',
stores: [
'app.store.MyTreeStore'
],
init: function () {
// this.getStore('MyTreeStore').on('beforeload', this.onBeforeLoad, this);
this.getStore('app.store.MyTreeStore').on('beforeload', this.onBeforeLoad, this);
// this.getAppStoreMyTreeStoreStore().on('beforeload', this.onBeforeLoad, this); <- You can also use this syntax
},
onBeforeLoad: function () {
alert('');
}
});

Cp_Barbossa
17 Sep 2012, 11:48 PM
Thx for replies.

I tried above examples, like
this.getStore('app.store.MyTreeStore').on('beforeload', this.onBeforeLoad, this);
and
this.getAppStoreMyTreeStoreStore().on('beforeload', this.onBeforeLoad, this);

So, now my store does not posts anything, but is does not steps in event function, i mean my event does not happens ( onBeforeLoad does not alerts ). :((

vietits
18 Sep 2012, 4:28 AM
Make sure your store class is loaded. What you post in your first post ("Get http://localhost/MyProject/scripts/app/store/MyTreeStore.js?_dc (http://wd/wd/wad/wadwd/wdwadwa/wdwadwd)=1347900348333 (http://localhost/MyProject/scripts/app/store/MyTreeStore.js?_dc=1347900348333)") is not store loading but Ext framework is trying to load MyTreeStore class file.