1

When I try to execute the code below, I get two Uncaught ReferenceError messages

Ext.define('Example.foo', {
  store: _createStore(),
  _createStore: function() {
    return new Ext.data.JsonStore({...});
  }
});
var example = new Example.foo();

The error messages:

Uncaught ReferenceError: _createStore is not defined
Uncaught ReferenceError: Example is not defined 

The error still occurs if _createStore is defined above store. I'm using ExtJS 4.2.1.883.

anjunatl
  • 1,027
  • 2
  • 11
  • 24

1 Answers1

1

If Foo is some UI component and you must use a function to get a reference to your store, you could do this:

Ext.define('Example.Foo', {

    // set other Foo properties...

    initComponent: function () {
        this.store = this.createStore();
        this.callParent(arguments);
    },

    createStore: function () {
        return Ext.create("Ext.data.JsonStore", {
            // store setup
        });
    } 

});

If you have a class that represents your store, though, you could just use the string name of the store class and the Ext framework will create an instance of it for you:

store: 'Example.stores.FooStore'
Chris Farmer
  • 24,974
  • 34
  • 121
  • 164
  • Awesome, calling it from `initComponent` is what I needed. A bit of googling lead me to [this SO post](http://stackoverflow.com/questions/14492179/to-initcomponent-or-not-to-initcomponent) that explains why it worked. – anjunatl Jul 16 '13 at 19:33