I’m using backbone with some nested models. I have a bunch of change handlers on the parent and child models for UI updating (simplified version below). The problem I have is that as soon as I call save() on the parent model and the JSON comes back from the server, the child model data is updated, but it is no longer recognized as a Backbone model, and my handlers all fail.
ChildModel = Backbone.Model.extend({
defaults: {
property: "property"
}
});
ParentModel = Backbone.Model.extend({
defaults: {
childModel: new ChildModel()
},
url : "resturl",
initialize: function () {
this.bind('change:childModel', this.changeHandler, this);
},
changeHandler: function () {
var child = this.get('childModel');
if(child instanceof Backbone.Model){
alert("is a backbone model");
} else {
alert("is not a backbone model")
}
}
});
var parent = new ParentModel();
parent.save()
When parent.save() is called, the model gets updated, but “is not a backbone model” gets alerted.
Check out my answer to your other question. I think it’s related:
https://stackoverflow.com/a/11368225/737318
If that’s not helpful, let me know.