淘汰赛数据绑定重置 [英] Knockout databind reset
问题描述
我在网络表单上使用剔除数据绑定.目前,我有一个重置功能,可在重新加载原始数据以清除表单之前使用它.我有60多个领域需要清除,每个人做起来都是一件痛苦的事情.有没有办法一次清除所有敲除绑定?目前,我使用的是以下内容:
I use knockout databinds on webforms. Currently I have a reset function that is used before re-loading original data to clear the form. I have over 60 fields that I need to clear and doing each one individual is a pain. Is there a way to clear all knockout bindings at once? Currently what I use is below:
self.parentObject.somefield('');
self.parentObjectAddress.street1('');
etc
etc
-更新1-
为澄清起见,我所有的字段都是parentObject的一部分.例子
To add clarification all my fields are part of a parentObject. Example
self.parentObject.fieldName
我要做的是清除parentObject的所有子对象.
What I am looking to do is clear all children of the parentObject.
推荐答案
我会考虑另一种方法.为什么不重置"对象本身,为什么不创建一个新对象并将旧对象扔掉呢?您应该已经具有用于创建对象的代码.如果您在顶层有data-bind="with: someObject"
(也许是<form>
标记?),则用新的干净"对象实例替换someObject(假设它是可观察的).
I would consider a different approach. Rather than "resetting" the object itself, why not create a new object, and throw the old one away? You should already have code to create the object. If you have a data-bind="with: someObject"
at the top level (maybe the <form>
tag?) then replace someObject (assuming it's observable) with a new, "clean" instance of the object.
这篇关于淘汰赛数据绑定重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!