PDA

View Full Version : Using a variable to determine which callback function to use in model.save



23 May 2013, 11:39 AM
I want to dynamically set my callback function through a variable but the functions are not being called even though the variable stores the function name. Has anyone done this before? Any suggestions? Thanks



Ext.define('ContentSchedule.controller.BasicAbstractController', {
extend: 'Ext.app.Controller',
saveContent: function () {
return this.save('contentCallback');
},
saveData: function () {
return this.save('dataCallback');
},
save: function (saveCallback) {
var frm = this.getForm(),
stsBar = this.getCreateStatusBar(),
rec;
if (frm.isValid()) {
try {
rec = this.getRecord();
rec.save({
callback: saveCallback
});
return true;
} catch (err) {
Ext.schdutil.err(this.errorSaveMessage, err);
}
} else {
this.setFormErrorMsg(stsBar, this.formErrorSaveMessage);
}
return false;
},
contentCallback: function (record, operation) {
alert("content");
},
dataCallback: function (record, operation) {
alert("data");
}
}


I want to utilize the same save routine but have different callbacks based on the type of data I am trying to save.

evant
23 May 2013, 4:16 PM
Because you're just passing a string:



return this.save(this.contentCallback);

28 May 2013, 11:35 AM
Thanks for the help evant.