Panciz
Panciz

Reputation: 2234

Ext JS accessing view and store from callback

When I writing the code of a ExtJS controller often happen that I need to access the store or the view from a callback function. The problem is that these references are in the scope of the controller and not in the scope of the function. For example if I want to reload the data of a grid I write a new record successfully:

    record.set(values);
    record.save( {
        callback: function(record, operation) {
            if (operation.wasSuccessful()) {
                Ext.Msg.alert("OK","User Created");
                var view=   Ext.getCmp('contactlist');
                view.getStore().load();
                            view.refresh();
            } else {
              Ext.Msg.alert("Error",operation.request.scope.reader.jsonData["error"]);
            }
    }});

After the user is created I want to refresh my store but I cannot use the view and store controller field since I'm in a different scope. Since now I use Ext.getCmp() to retrieve any component? Is this a good practice, which is the best way to solve these situations?

Upvotes: 1

Views: 963

Answers (1)

Jaimie Whiteside
Jaimie Whiteside

Reputation: 1220

You can use Ext.getStore('your.store.name'); to get the reference to the store and call whatever methods you want on it. Calling reload() on the store will fire the load event, which for things like grid views will trigger the view refresh

Upvotes: 1

Related Questions