Skip to content
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

[1.0.2] Databinding and nested objects #1731

Closed
robrez opened this issue Jun 3, 2015 · 2 comments
Closed

[1.0.2] Databinding and nested objects #1731

robrez opened this issue Jun 3, 2015 · 2 comments

Comments

@robrez
Copy link

robrez commented Jun 3, 2015

It seems that databinding a value from a nested object works only once. Here's an arbitrary example..

The markup...

<template>
    <div>
      <div>{{session.user.name}}</div>
      <div>{{session.user.id}}</div>
    </div>
    <button on-tap="_increment">Click</button>
  </template>

The script...

    properties: {
      session: {
          type: Object,
          value: function() { return { user: { name: "rob", id: 1 } }; }
      }
    },

    _increment: function() {
      this.session.user.id ++;
      console.log(this.session.user.id);
    },

I can see the id incrementing in the log, but the view never updates w/ the model.

I tried registering an observer on "session", it executes only once. A computed property, "computedId" is only computed once.

@arthurevans
Copy link

See:

https://www.polymer-project.org/1.0/docs/devguide/properties.html#observing-path-changes

You'll need to use the set API to update the object:

this.set('session.user.id', this.session.user.id+1);

@robrez
Copy link
Author

robrez commented Jun 3, 2015

Thanks so much, that works.

I figured there was something in the docs that I overlooked.

@robrez robrez closed this as completed Jun 3, 2015
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