视图未在可观察的更改上更新 [英] View not updating on observable changed

查看:85
本文介绍了视图未在可观察的更改上更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在更新列表的容器时重新呈现列表:

I'm trying to have a list be rerendered when the container of the list is updated:

{^{for selectedScenario.instances}}
     <div>{^{:name}}</div>
{{/for}}

当我使用$ .observable(data).setProperty("selectedScenario",方案)时,什么都没有改变.在 http://jsfiddle.net/ep76m4af/1/中,您可以看到此操作. ObserveAll显示数据本身已更新,并且事件已正确触发.

When I use $.observable(data).setProperty("selectedScenario", scenario), nothing changes. In http://jsfiddle.net/ep76m4af/1/ you can see this in action. ObserveAll shows that the data itself is updated and the event is properly fired.

推荐答案

不起作用的原因是因为您使用的是深层路径" selectedScenario.instances-默认情况下,它仅在叶子处监听"可观察到的变化水平,不深.要选择同时收听selectedScenario对象中的更改,而不仅仅是叶子instances属性,您需要将.替换为^,以表示您想在列表中更深入地收听.路径:

The reason it is not working is because you are using a 'deep path' selectedScenario.instances - which by default 'listens' to observable changes only at the leaf level, not deeper. To opt in to listening also to changes in the selectedScenario object, not just the leaf instances property, you need to replace the . by ^ to indicate that you want to listen down to a deeper level in the path:

{^{for selectedScenario^instances}}
     <div>{^{:name}}</div>
{{/for}}

请参阅本文档主题中的路径:叶子更改或深层更改部分: http://www.jsviews.com/#observe .

See the section Paths: leaf changes or deep changes in this documentation topic: http://www.jsviews.com/#observe.

另请参见本主题中的示例,例如示例:具有简单对象和数组的JsViews : http://www.jsviews.com/#explore/objectsorvm .

See also the examples such as Example: JsViews with plain objects and array in this topic: http://www.jsviews.com/#explore/objectsorvm.

此处更新了jsfiddle: http://jsfiddle.net/ep76m4af/2/

Updated jsfiddle here: http://jsfiddle.net/ep76m4af/2/

这篇关于视图未在可观察的更改上更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆