-
2 May 2012 8:16 AM #1
How to reference statics from one class when defining the data for a store
How to reference statics from one class when defining the data for a store
Hi all,
I have a mode defined with:
I am successfully referencing those static constants in another class via a requires:['...MyModel'] and then ...MyModel.KEY_A.Code:Ext.define('...MyModel', { extend: 'Ext.data.Model', statics: { KEY_A:'a', KEY_B:'b', .... and so on } ..... })
This is working great, except when I want to reference those statics when *defining* a class (rather than executing the code in a defined class). For example, I am defining a combobox which allows a user to choose a value, and its store is defined as:
however when I load that class I get an "Uncaught TypeError: Cannot read property 'KEY_A' of undefined".Code:var typeStore = Ext.create('....MyStore', { fields: ['type','name'], requires: ['....MYModel'], // for the constants data:[ {'type':...MyModel.KEY_A, 'name':'description of key a'}, {'type':...MyModel.KEY_B, 'name':'some description of key b'} ] });
Any ideas?
Thanks!
-
2 May 2012 8:24 AM #2
One more bit of context - I am creating the store outside of any Ext.defines:
Moving the myStore inline (so store: Ext.create...) or moving the definition of myStore into the init method works as expected. In other words, no hacking and doing it "properly" means it worksCode:var myStore = Ext.create('Ext.data.Store....) Ext.define('...MyView', { this.items: [ {xtype:combobox, store:myStore} ] });
-
2 May 2012 1:27 PM #3
You could create a constants file and list all your constants there:
/app/util/Constants.js
Then where you create the storeCode:KEY_A:'a', KEY_B:'b', .... and so on
Code:requires: ['MyApp.util.Constants'], // for the constants data:[ {'type':MyApp.util.Constants.KEY_A, 'name':'description of key a'}, {'type':MyApp.util.Constants.KEY_B, 'name':'some description of key b'}


Reply With Quote