Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Updating a live binded Observable object

$
0
0
Hi

I have an observable object on a user:

  1. user {
  2.    name:'Name',
  3.    addresses:[
  4.       {
  5.          'id':'1',
  6.          'street':'Street'
  7.       },
  8.       {
  9.          'id':'2',
  10.          'street':'Street'
  11.       }
  12.    ]
  13. }

Then I create an observable:

  1. User = new can.Observe(user);

In my EJS I have:

  1. Name: <%= User.attr('name') %><br>
  2. <% can.each(User.attr('addresses'), function() { %>
  3.     Street: <%= this.attr('street') %><br>
  4. <% } %>

Then I want to download a new user object from my server:

  1. var user = webServices.getUser() // returns new user in json format above

Then I kinda want to do this:

  1. User = new can.Observe(user);

And hope it will update the EJS automatically.

I have two worries:

1. Since I am actually creating a new object - the live binding on the old one will be lost.
2. The complex array in object structure won't really work with the live binding

How should I go about and solve this simple idea?

Viewing all articles
Browse latest Browse all 3491

Trending Articles