Skip to content

Instantly share code, notes, and snippets.

@yaotti
Created August 14, 2011 18:45
Show Gist options
  • Save yaotti/1145166 to your computer and use it in GitHub Desktop.
Save yaotti/1145166 to your computer and use it in GitHub Desktop.
Model.create({ success: function(){...}})とか書きたくないので関数追加した.もっと綺麗にできればいいんだけど無理そう.
// Return Backbone.sync's retval instead of the saved model
// to use the deferred object ($.ajax: jsdeferred.jquery.js).
Backbone.Collection.prototype.createDeferred = function(model, options) {
var coll = this;
options || (options = {});
model = this._prepareModel(model, options);
if (!model) return false;
return model.save(null, options);
};
// var collection = Backbone.Collection.extend();
// collection.createDeferred(this.newAttributes())
// .next(function(response) {
// var models = _(response).map(function(row) {
// return new SomeModel(row);
// });
// // do something...
// }).error(function(e) {
// console.error(e);
// });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment