如何为 Marionette 视图指定筛选的 Backbone collection

How to specify filtered Backbone collection for Marionette view

我有一个显示 collection 的 Marionette 复合视图,我在我的应用程序启动处理程序中设置了它:

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);
}); 

这按预期工作,显示了我的整个 collection。在我的模型中,我有一个状态字段,我只想显示状态为 0 的模型。我试过:

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

但这不起作用。我实际上想在 0 和 1 中显示状态,但我现在只想在 0 中显示状态。

我错过了什么?

问题可能在于 .where() 不是 return 集合,而是数组。 http://backbonejs.org/#Collection-where 这应该是为了保持与下划线的兼容性。

如果将行更改为:

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

有帮助吗?

我能够覆盖 Marionette CompositeView 中的过滤器方法:

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