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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:01:50+00:00 2026-05-26T09:01:50+00:00

I am attempting to bootstrap a backbone collection using an array of JSON objects

  • 0

I am attempting to bootstrap a backbone collection using an array of JSON objects like in the code below. However, when I try and call reset on the collection object I get an error from backbone – Uncaught TypeError: undefined is not a function.

If I change the JSON array to an array of Users.UserModel objects then it works. I must be missing something fundamental in the collection initialization method or something similar as all the examples I have seen don’t really contain much code than the call to reset.

class Users.UsersCollection extends Backbone.Collection
    model: Users.UserModel
    url: '/Users'

class Users.UserModel extends Backbone.Model

# document ready
$ ->
    Users.userCollection = new Users.UsersCollection()

    users = [
        { Id: 1, Username: 'dan', FirstName: 'Dan', LastName: 'Ormisher' },
        { Id: 1, Username: 'simon', FirstName: 'Simon', LastName: 'Lomax' },
        { Id: 1, Username: 'jon', FirstName: 'Jon', LastName: 'Swain' },
        { Id: 1, Username: 'martin', FirstName: 'Martin', LastName: 'Rue' }
    ]

    Users.userCollection.reset(users)

(I’m using coffeescript btw, but that is irrelevant)

  • 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-26T09:01:51+00:00Added an answer on May 26, 2026 at 9:01 am

    I just figured this out, I stepped through my code to the point in the backbone.js file where the error was happening, and found it was happening on line 570 (not minified obv). Where the collection was trying to use it’s own model property using this.model it was throwing the undefinded error.

    When I went back and looked at my code, I realised I was declaring the collection before the model, so when I was setting the collections’ model property it was setting it to undefined!

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

Sidebar

Related Questions

When attempting to call functions in math.h , I'm getting link errors like the
Im attempting to Convert a Price (from an API (code below)). public class Price
Attempting to render a model object into a JSON structure via a partial, like
Attempting to set up Samba + OpenLDAP using nss_ldap. After joining Windows7 to Samba
Attempting to generics-ify some legacy code, I'm stuck. I have a ParentObject which wraps
Just looked at the Bootstrap toolkit and attempting to get the dropdown's working on
Attempting to deserialize JSON data and update each object's prototype and inherit a common
Im attempting to add voteup/votedown to one of my sites, however Im having a
I am attempting to use Inno Setup to bootstrap a WiX generated .msi file
This is my first experience using the Zend Framework. I am attempting to follow

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.