mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
parse:true runs the attributes through parse():
`new Model(attr, {parse:true})` will now call
Model.prototype.parse(attr). This is useful if
you want to create a model out of an object
structure from an external server.
This commit is contained in:
@@ -51,6 +51,17 @@ $(document).ready(function() {
|
||||
equals(model.one, 1);
|
||||
});
|
||||
|
||||
test("Model: initialize with parsed attributes", function() {
|
||||
var Model = Backbone.Model.extend({
|
||||
parse: function(obj) {
|
||||
obj.value += 1;
|
||||
return obj;
|
||||
}
|
||||
});
|
||||
var model = new Model({value: 1}, {parse: true});
|
||||
equals(model.get('value'), 2);
|
||||
});
|
||||
|
||||
test("Model: url", function() {
|
||||
equals(doc.url(), '/collection/1-the-tempest');
|
||||
doc.collection.url = '/collection/';
|
||||
|
||||
Reference in New Issue
Block a user