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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:20:32+00:00 2026-06-15T02:20:32+00:00

I’m trying to do basic render() after fetch() on collection (Backbone 0.9.2): var ProjectListView

  • 0

I’m trying to do basic render() after fetch() on collection (Backbone 0.9.2):

var ProjectListView = Backbone.View.extend({
        el: $('#container'),
        initialize: function () {
            this.collection = new ProjectsCollection();
            this.collection.bind("change", _.bind(this.render, this));
            this.collection.fetch({ success: function () { console.log("collection fetched"); } });
            ...
             }, 
        render: function () {
            console.log("rendered");
            ...

Creating new View instance prints out:

    collection fetched 

So the render() never gets called after fetch(). What am I doing wrong here? There are no exceptions present.

Any tips how to debug these sort of things in backbone?

Ps.
It seems that this feature is poorly documented given the number of questions on SO.

  • 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-15T02:20:33+00:00Added an answer on June 15, 2026 at 2:20 am

    From the fine manual:

    fetch collection.fetch([options])

    Fetch the default set of models for this collection from the server, resetting the collection when they arrive. […] When the model data returns from the server, the collection will reset.

    And what does reset do? reset does this:

    reset collection.reset(models, [options])

    […] Use reset to replace a collection with a new list of models (or attribute hashes), triggering a single "reset" event at the end.

    So fetch calls reset to update the collection’s models and reset triggers a "reset" event, not a "change" event. None of the models have changed and a collection’s "change" events come from its models.

    You should have render bound to "reset":

    initialize: function () {
        this.collection = new ProjectsCollection();
        this.collection.bind("reset", _.bind(this.render, this));
        this.collection.fetch(...);
    }
    

    If you want to listen for "change" events on the contained models then you can bind a "change" handler to the collection since:

    You can bind "change" events to be notified when any model in the collection has been modified,
    […]
    Any event that is triggered on a model in a collection will also be triggered on the collection directly, for convenience.

    The collection will also generate "add" and "remove" events as the collection itself changes.


    Newer versions of Backbone no longer reset collections during fetch:

    When the model data returns from the server, it uses set to (intelligently) merge the fetched models, unless you pass {reset: true}, in which case the collection will be (efficiently) reset.

    And set:

    […] performs a “smart” update of the collection with the passed list of models. If a model in the list isn’t yet in the collection it will be added; if the model is already in the collection its attributes will be merged; and if the collection contains any models that aren’t present in the list, they’ll be removed. All of the appropriate "add", "remove", and "change" events are fired as this happens

    So with newer versions of Backbone you’ll want to list for the "add", "remove", and "change" events (which a collection based view should be listening for anyway); you could also use {reset: true} on the initial fetch and listen to "reset" as well. I’d recommend the following approach for collection based views:

    1. Listen to "add" and handle that event with a callback that simply adds one item to the view, don’t throw everything away and re-render.
    2. Listen to "remvoe" and handle that event with a callback that only removes the newly removed model.
    3. Listen to "change" and handle that with a callback that replaces (or updates) the appropriate item.
    4. Listen to "reset" and bind that to render. Then pass {reset: true} to the collection’s initial fetch call.

    That will trap the important events and the collection-view will do the minimal amount of work to handle each one. Of course, this strategy isn’t applicable to all situations but I think it is a good starting point.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

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.