Knockout databind reset

ε祈祈猫儿з 提交于 2019-12-23 16:17:19

问题


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

-- Update 1--

To add clarification all my fields are part of a parentObject. Example

self.parentObject.fieldName

What I am looking to do is clear all children of the parentObject.


回答1:


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.



来源:https://stackoverflow.com/questions/14382188/knockout-databind-reset

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!