Backbone error, Object add has no method 'bind'
items.bind 'add', (item) =>
@addOne(item)
addOne: (item) ->
view = new ListItem({model: item})
..initialization of the view throws this error: TypeError: Object add has no method 'bind'
class ListItem extends Backbone.View
el: $ '#wrap'
template: $ '#listItem'
initialize: () ->
@model.bind 'change', @render, @
@model.bind 'destroy', @remove, @
render: () ->
@el.append @template.tmpl @model.toJSON()
EDIT: logging item before setting the view results in...
I开发者_开发百科tem
_callbacks: Object
_changed: false
_changing: false
_escapedAttributes: Object
_previousAttributes: Object
attributes: Object
cid: "c2"
collection: Items
__proto__: ctor
but if I log @model when initializing the view it's an empty object called add
EDIT 2: item.bind is undefined from within addOne, not sure why though
Your code looks fine, but the object that you've added to items
doesn't appear to be a valid model. What code are you using for your items.add
call? Verify that you don't get an error when you run items.add(new Backbone.Model)
.
Perhaps you did
items.add [{foo: bar}]
but set the model
property on the Collection
class that items
is an instance of to something other than a Backbone.Model
subclass?
精彩评论