Skip to content

Instantly share code, notes, and snippets.

@AndrewIngram
Created February 22, 2013 10:30
Show Gist options
  • Save AndrewIngram/5012426 to your computer and use it in GitHub Desktop.
Save AndrewIngram/5012426 to your computer and use it in GitHub Desktop.
Tastypie Collection for Backbone.js
var TastypieCollection = Backbone.Collection.extend({
initialize: function(options) {
this.paginator = new models.Paginator({}, this);
},
parse: function(response) {
this.paginator.set(response.meta);
return response.objects || response;
},
patch: function(options){
var collectionPayload = {
'objects': []
};
this.forEach(function(model) {
var modelData = model.changedAttributes();
if (modelData) {
modelData.resource_uri = model.get('resource_uri');
collectionPayload.objects.push(modelData);
}
});
var syncOptions = _.extend({'attrs': collectionPayload }, options);
Backbone.sync('patch', this, syncOptions);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment