I’m currently trying to calculate a total flooring space using a form and the KnockoutJS tools. All has been setup and it’s working to the point of the calculation of the total floorspace.
The JsFiddle: http://jsfiddle.net/rmfloris/zmc0nzrr/24/
The visitor can add up to 4 differente spaces(self.ruimtes), which all need to be calculated to get to a total floorspacing (this.totaalOppervlakte). I have setup a computed function for the total floorspacing and a loop within this to go through all the ‘ruimtes’. When I run the code and use console.log it seems that it doesn’t loop through the array, which makes sense as the array is empty on start. But when I make a change to the array via the self.ruimtes.push() function, still nothing is happening.
this.totaalOppervlakte = ko.computed(function() {
var total = 0;
$.each(self.ruimtes, function() {
console.log('calculation')
total = total + self.Oppervlakte();
});
return total.toFixed(2);
});
Any idea why the ko.computed isn’t working as expected?