Skip to content

Question: Best way to listen for changes on deep nested objects. #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
swhamilton opened this issue Dec 26, 2014 · 1 comment
Open

Comments

@swhamilton
Copy link

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?

@jameslai
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants