如何强制刷新视图而不让它从 observable 自动触发? [英] How to force a view refresh without having it trigger automatically from an observable?

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

问题描述

注意:这主要是为了调试和理解 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 上调用某些东西,但是在单个 observable 上你可以调用 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.

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

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