Reputation: 1
I am new to backbone.js and attempting to use patterns that I have used in other languages. Some of them work and some have fallen quite flat. My questions is this - how should I reference my model from within a view. For example, I have 5 identicals views that I passed a model from a collection of models. When the user clicks one of the 5 views, I need it to use the model that it was created with. Right now, I am getting null for this.model anytime the user clicks the view.
Upvotes: 0
Views: 52
Reputation: 457
You need to pass the model in the view constructor as stated in the oficial doc http://backbonejs.org/#View-constructor then you can access the model from the view with just this.model
if your getting undefined and you have passed the model in the view's constructor, maybe is because of the context when the callback function is being called, have you checked that?
Upvotes: 1