Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8027817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:55:39+00:00 2026-06-04T23:55:39+00:00

I have two functions that loop through all models in a Backbone collection, and

  • 0

I have two functions that loop through all models in a Backbone collection, and save those that have been changed, or destroy those that have been selected for deletion. What I need to do is collate the success and errors, so that I can notify “X number of changes/deletions were successful” and/or “There was an error changing/saving X number of domains”.

I’ve no experience with saving/destroying Backbone collections, only models; and can’t find anything on the internet that shows how to do this.

The save and remove are called by events in the parent view.

The relevant code:

App.Views.SiteDomains = Backbone.View.extend({
    el: '.site-domains',
    initialize: function() {
        this.collection.on('all',this.render, this);
    },
    render: function() {
        $('.site-domains').empty();

    this.collection.each( function(model)
    {
        var view = new App.Views.SiteDomain({model: model});
        this.$('.site-domains').append(view.render().el);

        return this;
    });
},
saveDomainChanges: function() {

    this.collection.each( function(model)
    {
        var ref = model.get('ref');

        if ($('#' + ref).val() != model.get('domain')) {

            $('.save-domains').prop('disabled', true);

            var fields = $(this.el).find('form').serializeArray(), data = {};

            $.each(fields, function(i, pair)
            {
                data[pair.name] = pair.value;
            });

            model.save(data, {

                wait:true,
                success: function(model, response, event)
                {
                    // Pass each success to notification function
                },

                error: function(model, response, event)
                {
                    // Pass each error to notification function
                }
            });
        }
    });
    $('.save-domains').prop('disabled', false);
},
removeDomain: function() {
    this.collection.each( function(model)
    {
        var ref = model.get('ref');

        if ($('#remove-' + ref).prop('checked'))
        {
            model.destroy({
                wait:true,
                success:function() {
                    // Pass each success to notification function
                },
                error: function() {
                    // Pass each error to notification function
                }
            });
        }
    });
}
});

Many, many, many thanks in advance to anyone that can help with this! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:55:43+00:00Added an answer on June 4, 2026 at 11:55 pm

    You could use an event aggregator and create Model/View or just POJO for the notifications according to your app design. Something like this:

    // Event aggregator
    App.vent = _.extend({}, Backbone.Events);
    
    // POJO for the notifications
    App.notifications = {
        var onCreateSuccess = function (model, response) {
            ...
        };
        var onCreateError = function (model, response) {
            ...
        };
        App.vent.on('sitedomain:create:success', onCreateSuccess);
        App.vent.on('sitedomain:create:error', onCreateError);
    };
    
    // Add event triggering to corresponding callbacks
    model.save(data, {
        wait:true,
        success: function(model, response, event) {
            App.vent.trigger('createdomain:create:success', model, response);
        },
    
        error: function(model, response, event) {
            App.vent.trigger('createdomain:create:error', model, response);
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two functions that have different enough logic but pretty much the same
I have two functions that are supposed to encrypt and decrypt a string but
Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
I have created two functions that sum and subtract the numeric values of two
So I have two jquery functions that bassically do the same, but on 2
I have two fields that I'd like to match. (already done the validation functions
I have need for a function pointer that takes two arguments and returns a
I have an IF statement that consists of two separate function calls passing values
I have two functions in an ActionScript class, they are: private function loaderCompleteHandler(event:Event):void {
I have two functions whose underlying logic is the same but in one case

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.