Created
February 22, 2013 10:30
-
-
Save AndrewIngram/5012426 to your computer and use it in GitHub Desktop.
Tastypie Collection for Backbone.js
This file contains 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
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