When I add collection to the view like this:
var View = new MyCollectionView({ collection: new MyCollection() });
everything is okey. I can use this collection in initialize method (for binding events, for example). But how can I add another one?
I can’t do this way:
var View = new MyCollectionView({
collection: new MyCollection(),
secondCollection: new MySecondCollection()
});
From the fine manual:
So, if you create a view like this:
then Backbone will automatically assign
cto the view’sthis.collection. But if you create the view like this:then inside the View’s constructor:
So you can do this:
provided that your
MyCollectionViewhas aninitializemethod that knows to pull thesecondCollectionout of itsoptionsargument.Open your JavaScript console and have a look at what this does:
Demo: http://jsfiddle.net/ambiguous/XyeSD/