Skip to content

Instantly share code, notes, and snippets.

@julianitor
Created July 17, 2015 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julianitor/701c677279bac1529b88 to your computer and use it in GitHub Desktop.
Save julianitor/701c677279bac1529b88 to your computer and use it in GitHub Desktop.
Save all models of a Backbone collection if they changed.
Backbone.Collection.prototype.saveAll = function(options) {
return $.when.apply($, _.map(this.models, function(m) {
return m.hasChanged() ? m.save(null, options).then(_.identity) : m;
}));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment