I have a Marionette.CompositeView which needs to render a collection.
I would like to filter this collection on fetch and add action.
I tried with the following code (1) but I get the following error (2).
Any ideas, thanks.
(1)
var myCompositeView = Marionette.CompositeView.extend({
initialize: function () {
this.collection = app.taskCollection.where({type: 'todo'});
}
});
(2)
// Uncaught TypeError: Object has no method 'on'
Marionette’s CompositeView and CollectionView both expect the
collectionsetting to be a valid Backbone.Collection. Thewheremethod on Backbone’s collection does not return a Backbone.Collection, it return an array. So you have to wrap a collection around the results:Of course you can use any type that extends from Backbone.Collection. I just wanted to illustrate the point of it being a collection with this example.