I have encountered an issue with my view model where the bindings work correctly when adding objects to the observable array, but do not update when clearing the array.
To help illustrate the problem, I have created a jsfiddle and I am seeking guidance on how to resolve it:
http://jsfiddle.net/chriswnichols/gcywcce7/
function County(name) {
this.Name = name;
}
function ListCriteria() {
var self = this;
self.States = ko.observableArray([]);
self.Counties = ko.observableArray([]);
self.Zips = ko.observableArray([]);
self.Cities = ko.observableArray([]);
self.DobRanges = ko.observableArray([]);
self.Clear = function () {
self.States = ko.observableArray([]);
self.Counties = ko.observableArray([]);
self.Zips = ko.observableArray([]);
self.Cities = ko.observableArray([]);
self.DobRanges = ko.observableArray([]);
};
}
var ViewModel = function () {
var listCriteria = new ListCriteria(),
reset = ko.computed(function () {
listCriteria.Clear();
});
return {
listCriteria: listCriteria,
reset: reset
}
};
viewModel = new ViewModel();
ko.applyBindings(viewModel);
Any assistance in resolving this issue would be greatly appreciated. Thank you.