Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a Backbone.js View have a Model and a Collection?

Can a Backbone.js View have a Model and a Collection?

The reason I am asking is because I'm working with a View that holds a map with places plotted on it (using the leaflet library).

The Collection is of a group of models that hold coordinates to be plotted on the map.

The Model holds stuff like the map bounds and map shape.

Not sure how else to pull this one off...

Any help is appreciated, thanks!

like image 546
Chris Dutrow Avatar asked Jul 23 '12 22:07

Chris Dutrow


1 Answers

Yes, you can pass it in as simply as:

new view({model: m, collection: c});

and inside the view you can access both with:

this.model
this.collection

jsfiddle for example

like image 188
Andy Ray Avatar answered Nov 12 '22 23:11

Andy Ray