1. #1
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    215
    Vote Rating
    4
    colin.yates is on a distinguished road

      0  

    Default 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:

    Code:
    Ext.define('...MyModel', {
        extend: 'Ext.data.Model',
    
        statics: {
            KEY_A:'a',
            KEY_B:'b',
            .... and so on
        }
        .....
    })
    I am successfully referencing those static constants in another class via a requires:['...MyModel'] and then ...MyModel.KEY_A.

    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:

    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'}
            ]
        });
    however when I load that class I get an "Uncaught TypeError: Cannot read property 'KEY_A' of undefined".

    Any ideas?

    Thanks!

  2. #2
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    215
    Vote Rating
    4
    colin.yates is on a distinguished road

      0  

    Default


    One more bit of context - I am creating the store outside of any Ext.defines:

    Code:
    var myStore = Ext.create('Ext.data.Store....)
    Ext.define('...MyView', {
       this.items: [
         {xtype:combobox, store:myStore}
       ]
    });
    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 works

  3. #3
    Ext JS Premium Member
    Join Date
    Aug 2007
    Posts
    6
    Vote Rating
    0
    dsuzette is on a distinguished road

      0  

    Default


    You could create a constants file and list all your constants there:

    /app/util/Constants.js
    Code:
         KEY_A:'a',         
         KEY_B:'b',         
         .... and so on
    Then where you create the store
    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'}

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi