如何强制视图刷新而不使其从可观察对象自动触发? [英] How to force a view refresh without having it trigger automatically from an observable?

查看:106
本文介绍了如何强制视图刷新而不使其从可观察对象自动触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:主要用于调试和了解KnockoutJS.

Note: this is mostly for debugging and understanding KnockoutJS.

是否有一种方法可以显式地请求Knockout从(已绑定的)视图模型中刷新视图?我正在寻找类似的东西:

Is there a way to explicitly request Knockout to refresh the view from (already bound) view model? I am looking for something like:

ko.refreshView();

我了解这不是Knockout的预期用途,但我仍然想知道是否存在用于调试和学习目的的此类方法.

I understand that this is not an intended use of Knockout, but I still want to know if there is a such method for debugging and learning purposes.

推荐答案

您不能在整个viewModel上调用某些内容,但是在单个可观察对象上,您可以调用myObservable.valueHasMutated()通知订户应重新评估.正如您所提到的,在KO中通常不需要这样做.

You can't call something on the entire viewModel, but on an individual observable you can call myObservable.valueHasMutated() to notify subscribers that they should re-evaluate. This is generally not necessary in KO, as you mentioned.

这篇关于如何强制视图刷新而不使其从可观察对象自动触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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