Search code examples
backbone.jsmarionettebackbone-views

How to specify filtered Backbone collection for Marionette view


I have a Marionette composite view that displays a collection, which I set in my Application start handler:

App.on('start', function() {
  Backbone.history.start({pushState: true});

  // I load up this.appsCollection in my before:start handler
  var tblView = new this.appsTableView({
    collection: this.appsCollection
  });

  this.regions.main.show(tblView);
}); 

This works as expected, displaying my entire collection. In my models, I have a state field, and I want to display only models with state 0. I tried:

collection: this.appsCollection.where({state: 0})

but that doesn't work. I actually want to display states in 0 and 1, but I'm trying to just display state in 0 for right now.

What am I missing?


Solution

  • I was able to override the filter method in my Marionette CompositeView:

    http://marionettejs.com/docs/v2.4.3/marionette.collectionview.html#collectionviews-filter