mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-08 03:00:26 -04:00
Added clear method to Model. Removes all attributes like you would expect.
This commit is contained in:
16
backbone.js
16
backbone.js
@@ -190,6 +190,22 @@
|
||||
}
|
||||
return value;
|
||||
},
|
||||
|
||||
// Clears all attributes from the model, firing `"change"` unless you
|
||||
// choose to silence it.
|
||||
clear : function(options) {
|
||||
options || (options = {});
|
||||
var old = this.attributes;
|
||||
this.attributes = {};
|
||||
if (!options.silent) {
|
||||
this._changed = true;
|
||||
for (attr in old) {
|
||||
this.trigger('change:' + attr, this);
|
||||
}
|
||||
this.change();
|
||||
}
|
||||
return old;
|
||||
},
|
||||
|
||||
// Fetch the model from the server. If the server's representation of the
|
||||
// model differs from its current attributes, they will be overriden,
|
||||
|
||||
Reference in New Issue
Block a user