user1636522
user1636522

Reputation:

Persistent store load callback in ExtJS 4.1.1

I need a way to catch the JSON response every time my datastore has loaded. My first try was to use the autoLoad property but the callback fires only on first load :

autoLoad: {
    callback: function (records, operation) {
        // do something with operation.response.responseText
    }
}

So, I have decided to extend the load method :

load: function (options) {
    var callback = options && options.callback;
    return this.callParent([Ext.apply(options || {}, {
        callback: function (records, operation) {
            // do something with operation.response.responseText
            if (callback) {
                return callback.apply(this, arguments);
            }
        }
    })]);
}

It works, but I wonder if the framework already provides a more elegant solution.

Upvotes: 1

Views: 2529

Answers (1)

Reimius
Reimius

Reputation: 5712

You can add a load listener to the store and grab the current request from it's proxy when the load event is fired.

var myStore = Ext.create("Ext.data.store", {
   ...whatever here
   listeners: {
       load: function(store){
           store.getProxy().activeRequest.options.operation.response.responseText;
       }
   }
});

Thats if you want the response text specifically. If you want the response as a JSON object, you can use store.getProxy().reader.rawData; which is a little simpler

Upvotes: 2

Related Questions