mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-22 13:28:22 -05:00
Fixes #570, supports Model#save(key, value)
This commit is contained in:
11
backbone.js
11
backbone.js
@@ -291,7 +291,16 @@
|
||||
// Set a hash of model attributes, and sync the model to the server.
|
||||
// If the server returns an attributes hash that differs, the model's
|
||||
// state will be `set` again.
|
||||
save : function(attrs, options) {
|
||||
save : function(key, value, options) {
|
||||
var attrs;
|
||||
if (_.isObject(key) || key == null) {
|
||||
attrs = key;
|
||||
options = value;
|
||||
} else {
|
||||
attrs = {};
|
||||
attrs[key] = value;
|
||||
}
|
||||
|
||||
options = options ? _.clone(options) : {};
|
||||
if (attrs && !this.set(attrs, options)) return false;
|
||||
var model = this;
|
||||
|
||||
@@ -331,6 +331,15 @@ $(document).ready(function() {
|
||||
ok(_.isEqual(lastRequest[1], doc));
|
||||
});
|
||||
|
||||
test("Model: save in positional style", function() {
|
||||
var model = new Backbone.Model();
|
||||
model.sync = function(method, model, options) {
|
||||
options.success();
|
||||
};
|
||||
model.save('title', 'Twelfth Night');
|
||||
equals(model.get('title'), 'Twelfth Night');
|
||||
});
|
||||
|
||||
test("Model: fetch", function() {
|
||||
doc.fetch();
|
||||
ok(lastRequest[0], 'read');
|
||||
|
||||
Reference in New Issue
Block a user