Results 1 to 3 of 3

Thread: Using a variable to determine which callback function to use in model.save

  1. #1
    Sencha Premium Member
    Join Date
    Nov 2012
    Posts
    10

    Default Answered: Using a variable to determine which callback function to use in model.save

    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

    Code:
    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.

  2. Because you're just passing a string:

    Code:
    return this.save(this.contentCallback);

  3. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258
    Answers
    759

    Default

    Because you're just passing a string:

    Code:
    return this.save(this.contentCallback);
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  4. #3
    Sencha Premium Member
    Join Date
    Nov 2012
    Posts
    10

    Default

    Thanks for the help evant.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •