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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:31:33+00:00 2026-06-17T15:31:33+00:00

I have a backbone collection. I fetch. The server comes back with a JSON.

  • 0

I have a backbone collection. I fetch. The server comes back with a JSON. How do I populate the collection witht he fresh data? Here’s my code:

    var Todos = Backbone.Collection.extend({

       url: "server/todos-service.php", // this does what it is supposed to do so no worries!

       model: Todo,   

       initialize: function(attributes, options) {    
           // IN HERE WHAT DO I HAVE TO DO?
           // WHAT EVENT SHALL I BIND TO TO REACT THE DATA DELIVERY?
           // AND WHAT SHALL I DO NEXT TO POPULATE THE DAMN THINGS

           }
        });

    // CLIENT CODE
    new Todos().fetch();

Can anyone tell me how this is supposed to be done?

Cheers

  • 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-17T15:31:34+00:00Added an answer on June 17, 2026 at 3:31 pm

    The fetch will start the ajax call to your server. When the data is returned it is automatically put the data into your collection, and the collection will fire a reset being like “I’m done fetching data bro, you can use it now.”

    You would usually call fetch() from inside your view, and have the view listen to the reset event. When the reset event is trigger, the view renders the collection.

    var Todo = Backbone.Model.extend({
        // my model
    });
    
    var TodoList = Backbone.Collection.extend({
         url: myurl
         model: Todo   
        // my collection (usually nothing in the initialize function) 
    });
    
    
    var AppView = Backbone.View.extend({
      initialize: function() {
        // instantiate the collection
        this.collection = new TodoList();
    
        //listen to the reset event on the collection. When the reset event trigger, call the render function.
        this.collection.on('reset', this.render, this);
    
        // get the data from the backend
        this.collection.fetch();
      },
      render: function() {
         // render the collection like a boss
      }
    });
    
    //instantiate the view 
    var App = new AppView;
    

    Also as a resource, I found this tutorial to be really helpful in understanding the basics of backbone http://net.tutsplus.com/sessions/build-a-contacts-manager-using-backbone-js/

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

Sidebar

Related Questions

let's say I have : var Book = Backbone.Model.extend(); var Collection = Backbone.Collection.extend({ model:
I'm trying to have a collection in backbone that calls /search/:searchTerm to the server
I am trying to populate a collection with data from a JSON file. I'm
I have code that does this class MyCollection extends Backbone.Collection initialize: ({some_id}) -> super
I have a Backbone Collection initialized by running collection.fetch() method, and then after a
I have problems when i try to fetch data to my Backbone model from
I have a strange problem with the fetch of a backbone collection I am
I have a Backbone Collection of Models that have different data coming in on
(Edited to greatly simplify) On node I have the following server.js file. var Backbone
Here is what I have so far: var Item = Backbone.Model.extend({ defaults: { id:

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.