I think it is bad practice to “update” your viewModel. You can update it as follows:
ko.cleanNode(document.getElementById("element-id"));
ko.applyBindings(yourViewModel, document.getElementById("element-id"));
But I think that for a model of your kind called "reset", a cleaner method that returns your observables to their original states. Maybe like this:
function MyViewModel() {
this.something = ko.observable("default value");
this.somethingElse = ko.observable(0):
this.reset = function() {
this.something("default value");
this.somethingElse(0);
}
}
source
share