Hard to come up with a descriptive title, but what I want to achieve is the following:
- I have a Knockout Observable bound to a table row.
- I have an Edit-button which shows a number of input fields to the user, these fields are also bound to the same observable allowing the user to edit values inline in the table row.
- I want to save my observable in a temporary variable when the user clicks the Edit-button, so that I can undo the changes if the user wants to discard their edits.
How can I achieve this in a clean way with javascript? My object has methods in addition to plain properties.
These are the hacks that I'm aware of already:
- Convert my object to JSON and back. (Doesn't work with methods)
- Different kind of "clone" methods. (Haven't found any that works for me)
- Reload the data from the server and remap the observable.