Skip to content

Instantly share code, notes, and snippets.

@dogenpunk
Created August 7, 2012 12:17
Show Gist options
  • Save dogenpunk/3284854 to your computer and use it in GitHub Desktop.
Save dogenpunk/3284854 to your computer and use it in GitHub Desktop.
Backbone.js Collection with filters
RailsCollection = Backbone.Collection.extend({
initialize: function() {
_.bindAll(this, 'url');
},
url: function() {
var base = this.baseUrl || this.model.prototype.baseUrl;
if(!this.params) {
return base;
} else {
return base + '?' + $.param(this.params);
}
}
});
// Should also be able to do this by passing the 'data' option to the collection's
// fetch method.
RailsCollection = Backbone.Collection.extend({
});
coll = new RailsCollection();
var year_and_month = '2011-10';
coll.fetch({data: {date: year_and_month}});
// GET request to url?date=2001-10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment