PDA

View Full Version : Accessing a store in a function



webfriend13
21 May 2012, 3:00 AM
HI All,

I have a function in which I have defined a store.


var store = new Ext.create('Ext.data.ArrayStore', {
id: 'store',
autoLoad: false,
buffered: false,
pageSize: 200,
fields: myFields,
remoteSort: true,

});





I have another function in which I want to access this store. Usually I define the in separate file and use them in controller using getStoreNameStore(). Since this function is defined on the fly, how can i access it ?

Please provide your suggestions .

friend
21 May 2012, 3:33 AM
First off, the use of the 'new' keyword is not necessary when calling Ext.create().

Secondly, from the code sample/description, I'm guessing that you're not using MVC. Having said that, consider using namespacing:



Ext.ns('Myapp.stores');

Myapp.stores.myArrayStore = Ext.create('Ext.data.ArrayStore', {
autoLoad: false,
buffered: false,
pageSize: 200,
fields: myFields,
remoteSort: true,
});

function someAnonymousFunction() {
console.log('Store pageSize is ' + Myapp.stores.myArrayStore.pageSize);
};



You can then add other stores to the namespace and use/call them as you see fit.