7

I load my store as follows:

store.load({
    params: {
        paramMap
    },
    callback: function(records, options, success) {
        if (success) {
            var form = formPanel.getForm();
            var jsonStr = Ext.JSON.encode(records[0].raw);
            var jsonObj = Ext.JSON.decode(jsonStr);
            form.loadRecord(jsonObj);
        }
    }
});

The thing is I only want this call back to fire the first time the store is loaded. I want to remove it after that so that when I reload or load the store again it doesn't call this callback again.

Any idea, I tried getting the callback in the options config but that doesn't seem to work.

Narendra Jadhav
  • 10,052
  • 15
  • 33
  • 44
b3labs
  • 960
  • 1
  • 14
  • 29

1 Answers1

16

Not exactly sure what the problem is. The callback will only get called when the store is loaded with the callback.

store.load({callback:myCallback});
//callback will be called
store.load();
//callback will not be called

If you want to just do something once you might want to use a listener with single set to true. Listeners instead of callbacks is my preferred way.

store.on('load', onStoreLoad, this, {single:true});

The callback function arguments api is slightly different than a load listener, check the docs to see.

pllee
  • 3,909
  • 2
  • 30
  • 33
  • You are correct. I realized after putting a beforeload listener on the store. That I was actually calling reload which uses the same params as the original call which included my callback. So I switch it to call load. Thanks – b3labs Mar 27 '13 at 19:06
  • You may also need to pass scope in the first call: store.load({callback:myCallback, scope:this}); – What Would Be Cool Apr 29 '14 at 22:54