Created
July 29, 2012 07:02
-
-
Save tabouassaleh/3196469 to your computer and use it in GitHub Desktop.
Adding Filtering to Backbone.Marionette.CollectionView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| }); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var StarredListLayout = ListLayout.extend({ | |
| filter: function(item) { return item.get('is_starred'); }, | |
| templateHelpers: {pageTitle: 'Starred List'} | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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