This is my first time with backbone and I am trying to figure out why console.logging this.model inside of my view doesn’t spit out my model which has some default attributes.
Instead, I get:
function (){return a.apply(this,arguments)}
Here’s my fiddle: http://jsfiddle.net/amit_e/muLjV/33/
(Please open your console to see the results)
What am I doing wrong? How do I get access to my model inside my view?
As View doesn’t define a single model with
model:Photo. Ideally,Model:Photohas to be defined in a collection.You should create an instance of Photo inside View seperately. So, it will work.
When I added
var myPhoto = new Photo();in initialize block of view. I found this working then.About usage of Collection:
Collection is a group of Models. So, You should define it anywhere in View ( Initialize or render or cutom function). More specifically, Collection
is used in MVC architecture to perform operation on models collectively. For example, In your case Album could be a collection of Photos.
You can store multiple instances on photo in Album. Album will be useful to you in operations like search, sort, add, delete of photos.