I have computedone that is based on a property observableArray headers. I also have methods for adding and removing multiple headers:
function ViewModel() {
var self = this;
self.headers = ko.observableArray();
self.newHeaders = ko.computed(function() {
var countOfNew = 0;
ko.arrayForEach(self.headers(), function(header) {
if (!header.id) {
countOfNew++;
}
});
return countOfNew;
});
self.addHeaders = function(headers) {
ko.arrayForEach(headers, function(header) {
self.headers.push(header);
}
};
self.removeHeaders = function(headers) {
ko.arrayForEach(headers, function(header) {
self.headers.remove(header);
}
};
}
When I call addHeadersor removeHeaders, newHeadersis called for every element in the array headers. Is there any solution on how a temporary stop calculates the computed field? (e.g. ko.valueWillMutate, ko.valueHasMutatedused to subscribers).
source
share