Search code examples
sencha-touch-2undefinedstore

Not able to get store in sencha touch 2


I has define store in sencha touch as follow:

store.js

  Ext.define('bluebutton.store.BlueButton.Testing', {
    extend: "Ext.data.Store",
    requires: [
              'bluebutton.model.BlueButton.Testing'
    ],
    config: {
        storeId: 'testingstore',
        model: 'bluebutton.model.BlueButton.Testing'
    }
});

Model.js

    Ext.define('bluebutton.model.BlueButton.Testing', {
    extend: 'Ext.data.Model',

    requires: [
             'Ext.data.proxy.LocalStorage'
    ],

    config: {
        fields: [
            { name: 'first', type: 'string' },
            { name: 'second', type: 'string' }
        ],
        proxy: {
            type: 'localstorage',
            id: '_codeAnalyzerLocalStorage'
        }
    }
});

I need to call getStore()

    Ext.define('bluebutton.view.BlueButton.testing', {
    extend: 'Ext.form.Panel',
    xtype: 'testing',
       requires: [

    'bluebutton.view.BlueButton.TransactionList',
    'bluebutton.view.BlueButton.MemberPopUp',
     'bluebutton.view.BlueButton.MemberDetail',
     'bluebutton.store.BlueButton.MemberList',

     'bluebutton.model.BlueButton.Testing',
     'bluebutton.store.BlueButton.Testing'




    ],

    config: {
     id:'register',
        items :[

              {
                    xtype: 'textfield',
                    name: 'name',
                    label: 'Name'
                },
                {
                    xtype: 'emailfield',
                    name: 'email',
                    label: 'Email'
                },



                {

                    xtype: 'button',
                    text: 'Test Local',
                     handler: function(button) {


                       var test =   Ext.getCmp('testingstore').getStore();   

                       alert(test);





                       }




                },









        ],


   }

});

But I get this error

getStore is undefined

Please help. Thanks


Solution

  • you have to add your store in app.js

    you have to put your store in stores array,because of the sencha bug for storeId Referencing(as I know , js loading order of the app scripts),so if you want to use storeId,put your store in app.js.

    Ext.application({

    name : 'bluebutton',
    
    views : [ 'BlueButton.Testing', ],  
    
    stores : [ 'BlueButton.Testing', ], //this is the key
    
    
    models : [ 'BlueButton.Testing', ], 
    
    launch : function() {
        Ext.create('bluebutton.view.BlueButton.Testing');
    }
    

    });