Skip to content

Instantly share code, notes, and snippets.

@tabouassaleh
Created July 29, 2012 07:02
Show Gist options
  • Save tabouassaleh/3196469 to your computer and use it in GitHub Desktop.
Save tabouassaleh/3196469 to your computer and use it in GitHub Desktop.
Adding Filtering to Backbone.Marionette.CollectionView
onRender: function() {
var filter = this.options.filter || this.filter;
var view= new ListView({collection: TitanFile.channelList, filter: filter});
var contentPromise = this.content.show(view);
return contentPromise;
}
Backbone.Marionette.CollectionView.prototype.addChildView = function(item, collection, options) {
var filter = this.options.filter || this.filter;
if (filter && !filter(item)) return;
this.closeEmptyView();
var ItemView = this.getItemView();
return this.addItemView(item, ItemView, options.index);
};
Backbone.Marionette.CollectionView.prototype.showCollection = function() {
var filter = this.options.filter || this.filter;
var that = this;
var ItemView = this.getItemView();
this.collection.each(function(item, index){
if (filter && ! filter(item)) return;
that.addItemView(item, ItemView, index);
});
};
var StarredListLayout = ListLayout.extend({
filter: function(item) { return item.get('is_starred'); },
templateHelpers: {pageTitle: 'Starred List'}
});
var StarredListView = ListView.extend({
filter: function(item) { return item.get('is_starred'); },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment