PDA

View Full Version : Accessing helper class variable in stores



webfriend13
13 Mar 2012, 10:50 PM
Hi All,

I am using ExtJs framework 4.0. I have created a store which requires two extraParams while calling the proxy. Following is the code.

proxy: {
type: 'ajax',
url: '/getData',
extraParams: {
connName: MyApp.common.Connection.getConnName(),
userName: MyApp.common.Connection.getUserName()
},
...
}

The store have a requires config
requires: ['MyApp.common.Connection' ],

In App.Js i have defined
Ext.Loader.setConfig({
enabled: true,
setPath:
{
'MyApp.common': '././common'
}
});

I am able to use MyApp.common.Connection.getUserName() & MyApp.common.Connection.getConnName in controllers and views but not in store.

when I try to use MyApp.common.Connection.getUserName() in store to pass it as extraParam, it says MyApp.common is undefined

What needs to be done here?
Also If it is not feasible, what other alternative we have to access data in stores?

Thanks in advance

vietits
13 Mar 2012, 11:33 PM
It's because MyApp.common.Connection is not available at defining time. So let move it into store constructor. Something like this:


requires: ['MyApp.common.Connection'],
proxy: {
type: 'ajax',
url: '/getData'
},
constructor: function(){
var me = this;
Ext.apply(me.proxy, {
extraParams: {
connName: MyApp.common.Connection.getConnName(),
userName: MyApp.common.Connection.getUserName()
}
});
me.callParent(arguments);
},
...
}