Skip to content

Instantly share code, notes, and snippets.

@jacobthemyth
Created June 15, 2015 20:03
Show Gist options
  • Save jacobthemyth/c4c41601e2b84a890993 to your computer and use it in GitHub Desktop.
Save jacobthemyth/c4c41601e2b84a890993 to your computer and use it in GitHub Desktop.
var Bookmark = Backbone.Model.extend({
idAttribute: '_id',
defaults: function(){
return {
url: '',
tags: []
};
}
});
var BookmarkCollection = Backbone.Collection.extend({
url: "http://tiny-lasagna-server.herokuapp.com/collections/bookmarks"
});
var bookmarks = new BookmarkCollection();
var filteredBookmarks = bookmarks.clone();
var tag = new Backbone.Model();
function filterBookmarks() {
filteredBookmarks.reset( bookmarks.filter(function(b) {
return _.contains(b.get('tags'), tag.get('selected'));
}));
}
tag.on('change:selected', filterBookmarks);
tag.set('selected', 'cool');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment