mikeric / rivets

Lightweight and powerful data binding.
http://rivetsjs.com
MIT License
3.23k stars 309 forks source link

Can we use this with a nested JSON object #68

Closed satyasuman closed 11 years ago

satyasuman commented 12 years ago

Hi, does this work when we have a deeply nested JSON object?

mikeric commented 12 years ago

That really depends on your model objects and if they support observing nested keypaths or not. If they do, then just make sure your adapter.subscribe implementation is subscribing to them in the same way you would subscribe to nested keypaths. Depending on how your models work, you may also need to change your adapter.read and adapter.publish implementations.

If you mean just accessing (not binding to) a deeply nested value in an object using the adapter bypass, then no, that's not supported at the moment, you would have to pass those nested objects as contexts when doing rivets.bind.

For example if you have this structure:

user =
  fname: "Bob"
  lname: "Vance"
  profile:
    email: "bob@vancerefrigeration.com"
    company: "Vance Refrigeration"

And you wanted to bind to values that are at the user root, and values that are on user.profile:

rivets.bind el, user: user, user_profile: user.profile
<span data-text="user:fname"></span>
<span data-text="user_profile:email"></span>