Knockout databind reset

2019-07-05 13:53发布

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.

标签: knockout.js
1条回答
Evening l夕情丶
2楼-- · 2019-07-05 14:46

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.

查看更多
登录 后发表回答