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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:59:00+00:00 2026-05-25T15:59:00+00:00

I have a collection of models. When a model changes it triggers a change

  • 0

I have a collection of models. When a model changes it triggers a change event on the collection. I watch for the collection change event and then I update the UI.

How should I go about updating the UI? Don’t I need to know what models are new, so I can append, and what already exist, so I can update?

One of the reason I feel I need this granularity is because there’s an animation transition, so I need to relate every model to it’s previous state. Does backbone help with this or should I just build this on my own?

  • 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-05-25T15:59:01+00:00Added an answer on May 25, 2026 at 3:59 pm

    to know which models are new, listen to the collection’s “add” event. then you can render the individual item.

    
    MyView = Backbone.View.extend({
    
      initialize: function(){
        _.bindAll(this, "renderItem");
        this.collection.bind("add", this.renderItem);
      },
    
      renderItem: function(item){
        // render the new item here
      },
    
      render: function(){
        this.collection.each(this.renderItem);
      }
    });
    

    in this example, rendering the collection works the same as rendering an individual item – it calls the same renderItem method that the “add” event calls.

    to handle the scenario where you have a sorted list… you’ll have to do some logic in your renderItem method to figure out the location of the item. something like this maybe (untested code… just an idea):

    
    MyView = Backbone.View.extend({
    
      initialize: function(){
        _.bindAll(this, "renderItem");
        this.collection.bind("add", this.renderItem);
      },
    
      renderItem: function(item){
        var itemView = new ItemView({model: item});
        itemView.render();
        return itemView;
      },
    
      render: function(){
        this.collection.each(function(item){
          var itemView = renderItem(item);
          var itemIndex = item.get("index");
          var previousItem = this.$(".myList")[itemIndex];
          $(itemView.el).insertAfter($(previousItem));
        });
      }
    });
    

    this code assumes you have an index attribute on your models to know the order that the models are supposed to be in.

    also note that there’s a high likelihood that this code won’t execute as-is, since i haven’t tested it out. but it should give you an idea of the code you’ll want to write.

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

Sidebar

Related Questions

Lets say we have the following models: (simplified) class Collection(models.Model): slug = models.SlugField() class
i am new to .net 3.5. I have a collection of items: IList<Model> models;
I have the following Backbone.js model and collection: // Model lr.Event = Backbone.Model.extend({}); //
I have this json which populates my collection ( TableListCollection ) of models (
I have a Backbone View that has a Collection as its Model. If the
My collection.fetch doesn't work and doesn't get the models to be rendered. I have
I have co-workers working on an Entity Framework model that changes structure (entities), over
I have got an Entity model which contains a collection of Message objects which
Imagine a model like this: class CFile(models.Model): filepath = models.FileField(upload_to=...) collection = models.ForeignKey(FileCollection,null=True) ...
I have a Model than contains a collection of items that can be modified.

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.