You have two problems:
ko.observable
returns a function so you need to get its value with calling it as a function with()
. For example:self.column1()
andself.column1()
- by default the
this
inside a computed is not the "current" object so you should useself
instead (or passthis
as the second argument ofko.computed
)
So the fixed sum
would look like this:
self.sum = ko.computed(function(){
var col1 = isNaN(parseInt(self.column1())) ? 0 : parseInt(self.column1());
var col2 = isNaN(parseInt(self.column2())) ? 0 : parseInt(self.column2());
return col1 + col2;
});
Demo JSFiddle.