Skip to content

Instantly share code, notes, and snippets.

@h2rd
Created December 15, 2012 19:31
Show Gist options
  • Select an option

  • Save h2rd/4298452 to your computer and use it in GitHub Desktop.

Select an option

Save h2rd/4298452 to your computer and use it in GitHub Desktop.
Backbone fetch with parameters
MessageList = Backbone.Collection.extend({
initialize: function(models, options) {
options = options || {};
this.offset = options.offset || 0;
this.limit = options.limit || 30;
this.sortBy = options.sortBy || 'by_desc';
},
url: function() {
return '/messages?' +
'offset=' + encodeURIComponent(this.offset) + '&' +
'limit=' + encodeURIComponent(this.limit) + '&' +
'sort_by=' + encodeURIComponent(this.sortBy);
},
parse: function(response) {
// Parse models
// Parse offset, limit, sort by, etc
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment