Veronica Lotti Veronica Lotti - 1 year ago 187
Javascript Question

Backbone options to fetch a callback success

subscribe: function () {{email: email}, {
success: function (data) {
var msg = view.model.getSuccessMessage(view._SiteInstance.get('paid_features'));
view.notify({message: msg, timeout: 7000});
this.storageKey = 'email_subscribe';
localStorage.setItem(this.storageKey, true);


This is what I need to override in order to show my confirm message into my pop up and not to call view.notify

My function belongs to a oneView.

A pop up form is calling myFunction (from another view).

I want to call myFunction from my view and override it (I need to override the success callback) with Backbone.

Answer Source

You can override your model's `save method and inject your success function there.


    // Overwrite save function
    save: function(attrs, options) {
        options || (options = {});
        attrs || (attrs = _.clone(this.attributes));
        var oldSuccess = options.success || function() {};

        options.success = function(result){
            //you code goes here

        // Proxy the call to the original save function, attrs, options);

Overriding is taken from this question: Exclude model properties when syncing (Backbone.js)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download