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

The Archive Base Latest Questions

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

I am bootstrapping all my important data in my backbone app on my initial

  • 0

I am bootstrapping all my important data in my backbone app on my initial page load. This is mainly collections. I have been stuck for a while on an issue where I was calling collection.get(id) but it was returning undefined even though I knew a model with an ID attribute of the passed ID existed.

Then when I inspected the collection in the console I noticed that the _byId array which should contain an array of my models ID’s is empty.

You can see from the console print out below that the collection does have models, and those models have an ID attribute.

window.campaigns
child
  _byCid: Object
  _byId: Object
    __proto__: Object
  _callbacks: Object
  length: 32
  models: Array[32]
  models: Array[32]
  0: child
    _callbacks: Object
    _escapedAttributes: Object
    _pending: Object
    _previousAttributes: Object
    _silent: Object
    attributes: Object
    DateCreated: "23/05/2012"
    DateScheduled: ""
    DateSent: ""
    Description: null
    From: null
    ID: 1
    IsAllowed: false
    Message: null
    Name: "Some name"
    __proto__: Object
    changed: Object
    cid: "c0"
    collection: child
    __proto__: ctor
  1: child
  2: child
  3: child
  4: child
  5: child
  length: 6
  __proto__: Array[0]
  __proto__: ctor

I am bootstrapping the data using an array of JSON objects which are written to my index page on page load. I assumed that that is all you had to do, and Backbone would assume that a property called ‘ID’ is the ID of the model and would interpret accordingly.

Am I wrong in thinking this/am I doing this correctly?

  • 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-04T16:58:57+00:00Added an answer on June 4, 2026 at 4:58 pm

    I see this in your model:

    ID: 1
    

    JavaScript is case sensitive so id and ID are different things; Backbone is looking for id by default and doesn’t know anything about ID.

    If you use id then everything will work out of the box:

    ​var M = Backbone.Model.extend({});
    var C = Backbone.Collection.extend({
        model: M
    });
    ​var c = new C([
        { id: 1, str: 'where'    },
        { id: 2, str: 'is'       },
        { id: 3, str: 'pancakes' },
        { id: 4, str: 'house?'   }
    ]);
    

    Demo: http://jsfiddle.net/ambiguous/nzLEC/

    Or you could tell your model to use a different attribute for the id by using idAttribute:

    idAttribute model.idAttribute

    A model’s unique identifier is stored under the id attribute. If you’re directly communicating with a backend (CouchDB, MongoDB) that uses a different unique key, you may set a Model’s idAttribute to transparently map from that key to id.

    The first sentence of the description might be better phrased as

    A model’s unique identifier is stored under the id property.

    to avoid some of the common confusion between JavaScript object properties and Backbone model attributes.

    For example:

    var M = Backbone.Model.extend({
        idAttribute: 'ID'
    });
    var C = Backbone.Collection.extend({
        model: M
    });
    var c = new C([
        { ID: 1, str: 'where'    },
        { ID: 2, str: 'is'       },
        { ID: 3, str: 'pancakes' },
        { ID: 4, str: 'house?'   }
    ]);
    

    Demo: http://jsfiddle.net/ambiguous/3NhGV/

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

Sidebar

Related Questions

I'm using Backbone.js and thus bootstrapping data using a JSON (jbuilder) partial like so
I am working on some code to load some bootstrapping data into my Grails
I'm writing a ruby bootstrapping script for a school project, and part of this
I heard about the chicken and the egg and bootstrapping. I have a few
This is a tricky one. I am emulating ZF Bootstrapping (surface appearance). Don't ask
Zend framework is pretty fast growing, we all agree and we all had been
This is my StructureMap bootstrapping: ObjectFactory.Initialize(factory => { //Business Conversation is per session factory.ForRequestedType<IConversation>().
Roslyn is written in C# with some initial bootstrapping. Does it pave the way
I currently have an iOS app that can 'bootstrap' it's database from a bunch
I am adding nodes to my existing cassandra cluster. Bootstrapping got stuck after Node

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.