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 7830507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:15:50+00:00 2026-06-02T11:15:50+00:00

If I initialize a collection with an array of objects for the model attributes

  • 0

If I initialize a collection with an array of objects for the model attributes when a dialogview is initialized. Then the dialog view that lets the user edit the list updates those model values with calls to model set. When the dialog’s ok button is clicked, Does backbone provide a way to get the list of only those models that changed since the collection was created/initialized?

  • 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-02T11:15:51+00:00Added an answer on June 2, 2026 at 11:15 am

    There are various model methods that look tempting:

    • Model#hasChanged
    • Model#changedAttributes
    • Model#previous
    • Model#previousAttributes

    But don’t be fooled, those only apply while a "change" event is being triggered:

    Note that this method, and the following change-related ones, are only useful during the course of a "change" event.

    so they’re useless after the event has been triggered and handled.

    I think you have to track which models have changed yourself. You can do this on the collection itself without too much effort since

    Any event that is triggered on a model in a collection will also be triggered on the collection directly, for convenience.

    and the collection can bind to its own events. For example, you could have something like this in your collection:

    Backbone.Collection.extend({
        initialize: function() {
            this.delta = { };
            this.on('change',​​​​​ this._a_model_has_changed);
        },
        changed_models: function() {
            return _.chain(this.delta).values();
        },
        _a_model_has_changed: function(m) {
            this.delta[m.id] = m;
        }
    });
    

    Then you could get the models that have changed by calling collection.changed_models(). You’d want to listen for other events as well so that you could update this.delta when models are deleted or synced with the server; the above is just for illustration. If you didn’t want an Underscore object returned you could use this instead:

    changed_models: function() {
        return _(this.delta).values();
    }
    

    but being able to collection.changed_models().each(function() { ... }) is convenient.

    Demo: http://jsfiddle.net/ambiguous/8PQh9/

    You could also let the models track their own dirtiness through a similar set on the models. Then you could do something like this:

    collection.filter(function(m) { return m.is_dirty() });
    

    where, of course, is_dirty would return true if the model had been changed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of objects that I'm trying to add to the Items
Garbage collection in .NET leads many to believe that lightweight objects can be treated
I've got a Backbone model line that contains a collection of the model Stop
I have this class: public MyClass { public void initialize(Collection<String> data) { this.data =
To initialize an int array with all zeros, do I need to use: int
I initialize the tweet button at the beginning of my app, after user interaction
I've got a backbone model with contains a collection. The output from the console
I have a backbone model which contains an array which I am updating with
In Java is there anyway to have one constructor that will accept an array
Is there a way in Spring to create a collection, or array, of beans,

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.