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

How to observe property array properly? #437

Closed Dissolubilis closed 5 years ago

Dissolubilis commented 5 years ago

Hello, How can I observe (or set 'depends' for computed observable) for changing of array items properties?

I.E.

{ property : [ 
  {items: [{x:1}]}, 
  {items: [{x:2}]}
] };

Now how can I observe only length of all 'items' arrays? depends = ["**"] is working, but what exact path for observing such properties? There is JsFiddle with example of what I want to achieve https://jsfiddle.net/rp3khq1z/4/

BorisMoore commented 5 years ago

Looks like you figured it out?

data.total.depends = "property.[].items.length";
// or data.total.depends = ["property.[].items.length"];

Right?

Dissolubilis commented 5 years ago

Right, thank you. But I've realised it is not the example I wanted to show. I still have some issue in project, when only greedy path "**" is working for observing nested arrays length in root array, but I cannot reproduce it alone yet. If I find it, I wll reopen issue