BorisMoore / jsviews

Interactive data-driven views, MVVM and MVP, built on top of JsRender templates
http://www.jsviews.com/#jsviews
MIT License
855 stars 130 forks source link

observable setProperty does not work if value is an object #318

Closed markibanez closed 8 years ago

markibanez commented 8 years ago

Hi Boris,

I'm not sure if there's a way to do this or if this is at all possible. I'm trying to set an object using setProperty, like so $.observable(model).setProperty('active_tool', model.tools.selection) .

I made a jsfiddle to show you what I mean: https://jsfiddle.net/2x7mq7cy/5/

When having an object as a value, it just seems to break data binding.

Thanks in advance

BorisMoore commented 8 years ago

Hi Mark,

The reason it is not working is because you are using a 'deep path' active-tool.name - which by default 'listens' to observable changes only at the leaf level, not deeper.

You need to write

<input type="text" data-link="{:active_tool^name trigger=true:}" />

(or <input type="text" data-link="active_tool^name trigger=true" />

Update fiddle: https://jsfiddle.net/BorisMoore/2x7mq7cy/6/

See also: http://stackoverflow.com/questions/32334729/view-not-updating-on-observable-changed

markibanez commented 8 years ago

Thanks Boris! This is a game changer for me :+1: