Created
August 7, 2012 12:17
-
-
Save dogenpunk/3284854 to your computer and use it in GitHub Desktop.
Backbone.js Collection with filters
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
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