A. Sinha
A. Sinha

Reputation: 2716

Unable to modify variable from within callback in ExtJs

How can the value of variable 'updated', be modified in the code below from within callback.

Why the variable 'updated' is not getting modified in the following manner (i.e. it returns false every time function is invoked)?

updateData:function()
{
    var updated = false;
    var store = new Ext.getStore('MyStore');
    store.load({
        scope: this,
        callback: function(records, operation, success) {
         if(/*some condition*/){
            updated=true;   
          }
        }
    });

return  updated ;
}

Upvotes: 1

Views: 65

Answers (1)

Sergey Novikov
Sergey Novikov

Reputation: 4196

Not sure what exactly you want to achieve with this piece of code, but since store.load() is asynchronous (I assume that you use remote proxy like ajax) store is not loaded when you return updated so its still false.

If you just want do something when store is loaded you can do it within callback anonymous function (or pass callback function to your updateData function and call it within callback?).

If you want to check if store is loaded or not you can call isLoaded() for ExtJS 5+ or check for store lastOptions property (if that exists then your store has loaded at least once) property for ExtJS 4.

I do not see adequate solutions to your updateData function returns true.

Upvotes: 1

Related Questions