在视角中从视图中取消绑定视图模型 [英] Unbind view model from view in knockout

查看:205
本文介绍了在视角中从视图中取消绑定视图模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在淘汰赛中寻找解绑功能。不幸的是,使用谷歌搜索和查看这里提出的问题并没有给我任何关于这个主题的有用信息。



我将举例说明需要哪种功能。 / p>

可以说我有一个有几个输入的表单。
我也有一个视图模型绑定到这种形式。
出于某种原因,作为对用户操作的反应,我需要从窗体中取消绑定我的视图模型,即,由于操作完成,我希望所有可观察对象停止对相应值的更改作出反应,反之亦然 - 任何更改都已完成观察对象不应影响输入值。



实现此目的的最佳方法是什么?

解决方案

您可以使用 ko.cleanNode 删除绑定。您可以将其应用于特定的DOM元素或更高级别的DOM容器(例如整个表单)。

请参阅 http://jsfiddle.net/KRyXR/157/ 为例。

I'm looking for unbind functionality in knockout. Unfortunately googling and looking through questions asked here didn't give me any useful information on the topic.

I will provide an example to illustrate what kind of functionality is required.

Lets say i have a form with several inputs. Also i have a view model binded to this form. For some reason as a reaction on user action i need to unbind my view model from the form, i.e. since the action is done i want all my observables to stop reacting on changes of corresponding values and vise versa - any changes done to observables shouldn't affect values of inputs.

What is the best way to achieve this?

解决方案

You can use ko.cleanNode to remove the bindings. You can apply this to specific DOM elements or higher level DOM containers (eg. the entire form).

See http://jsfiddle.net/KRyXR/157/ for an example.

这篇关于在视角中从视图中取消绑定视图模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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