Created
April 13, 2011 23:26
-
-
Save andrewdeandrade/918650 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The following is your top-level parent model in serialized JSON format: | |
var myModel = new Person({ | |
"name" : { | |
"first_name" : "Andrew", | |
"last_name" : "de Andrade" | |
}, | |
"address" : { | |
"street_address_1" : "Avenida Paulista 1000", | |
"street_address_2" : "Apt. 101", | |
"zip_code" : "12345-0000" | |
}, | |
"vehicle" : { | |
"make" : "Toyota", | |
"model" : "FJ-40 Landcruiser", | |
"year" : "1966", | |
"VIN" : "123456789ABCDEF" | |
} | |
}); | |
// Parent Model: | |
Person = Backbone.Model.extend({ | |
defaults: { | |
"name" : new Name, | |
"address" : new Address, | |
"car" : new Car | |
}, | |
initialize: function() { | |
this.set({ | |
"name" : new Name(this.get('name')), | |
"address" : new Address(this.get('address')), | |
"car" : new Car(this.get('car')) | |
}); | |
} | |
}); | |
// Children Models: | |
Name = Backbone.Model.extend({ | |
defaults: { | |
"first_name" : "", | |
"last_name" : "", | |
}, | |
initialize: function() { | |
} | |
}); | |
Address = Backbone.Model.extend({ | |
defaults: { | |
"street_address_1" : "", | |
"street_address_2" : "", | |
"zip_code" : "00000-0000" | |
}, | |
initialize: function() { | |
} | |
}); | |
Car = Backbone.Model.extend({ | |
defaults: { | |
"make" : "", | |
"model" : "", | |
"year" : null | |
"VIN" : null | |
}, | |
initialize: function() { | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment