Possible Duplicate:
knockoutjs: can we create a dependentObservable function with a parameter?
In my viewmodel, I have a function that returns the sum of items based on the type of item:
var ViewModel = function(data) {
var self = this;
this.Results = ko.observableArray(data);
this.totalPerType = function(type) {
var total = 0;
for (var index in self.Results()) {
if (self.Results()[index].Type == type)
total += self.Results()[index].Quantity;
}
return total;
};
};
When the user edits one of the items, the total isn't updated automatically, because it isn't a computed observable. Is it possible to change the function totalPerType into a computed observable, without having to put the type parameter into the viewmodel (keeping it as a parameter)?
I created a Fiddle to make it easier to try some things: http://jsfiddle.net/7PK9r/