Easiest way to reset Backbone’s model to initial defaults?
myModel.clear().set(myModel.defaults);
myModel.clear().set(myModel.defaults);
While this.model.get(“obj1”).myAttribute1 is fine, it’s a bit problematic because then you might be tempted to do the same type of thing for set, i.e. this.model.get(“obj1”).myAttribute1 = true; But if you do this, you won’t get the benefits of Backbone models for myAttribute1, like change events or validation. A better solution would be to never nest … Read more
I have the very same issue while I’m writing my Backbone application. Having to deal with embedded/nested models. I did some tweaks that I thought was a quite elegant solution. Yes, you can modify the parse method to change a attributes around in the object, but all of that is actually pretty unmaintainable code IMO, … Read more