backbone-associations
backbone-associations copied to clipboard
Question: Best way to listen for changes on deep nested objects.
I need similar functionality to what Backbone-nested provides. I need to listen to an event change on a deep nested object, but I don't really need the extra features that backbone-associated offers.
data from server:
{
name: "test",
photo: {
profile: {
prefix: "http://",
suffix:"profile.jpg"
},
team: {
prefix: "http://",
suffix:"team.jpg"
}
}
}
I would listen to the change event on the photo.profile and photo.team object, which are simple models:
var Photo = Backbone.Model.extend({
default: {
prefix: "",
suffix: ""
}
});
Is there a simple way to achieve this with backbone-associations? Or I should use both BB-associations in conjunction with BB-nested or BB-deep-model?
Yes, you can listen for nested-change
events on the parent model as long as you set Backbone.Associations.EVENTS_NC
to true
. There is a bit of documentation for this on the [events documentation](Backbone.Associations.EVENTS_NC = true) page.