anjunatl
anjunatl

Reputation: 1057

Unable to call method in ExtJS class from inside the class

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.

Upvotes: 1

Views: 1271

Answers (1)

Chris Farmer
Chris Farmer

Reputation: 25386

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'

Upvotes: 1

Related Questions