A
A
Artem Lipatov2015-07-10 23:50:49
backbone.js
Artem Lipatov, 2015-07-10 23:50:49

How to remove Uncaught TypeError: Cannot read property 'idAttribute' of undefined in Backbone Collection?

Coffeescript code:

UserNameModel =
  # idAttribute: 'id'
  defaults:
    "Name": ""

ProjectGroup = Backbone.Collection.extend
  model: UserNameModel
  checkUser: (username) ->
    findResult = @find (user) -> user.get "Name" == username
    findResult != null

SE1 = new ProjectGroup [
  {id: 1, Name: "Artem"}
  {id: 2, Name: "Airat"}
  {id: 3, Name: "Vlad"}
  {id: 4, Name: "Maxim"}
  {id: 5, Name: "Igor"}
]

On startup, Uncaught TypeError: Cannot read property 'idAttribute' of undefined, points to the line where SE1 is created.
How to make the code work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-07-11
@Rendalf

First, idAttribute must be specified on the model, not on the collection.
Secondly, if you have it equal to 'id', then you do not need to specify it at all - this is the default value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question