I have a javascript section that reads a json and populates an observablearry and subsequently an ojet table as below:
$.getJSON("api-detail.json").
then(function (forecast){
$.each(forecast, function() {
self.forecastArray.push({
rank: this.rank,
rep: this.rep,
total: this.total
});
});
});
self.ForecastDatasource = new oj.ArrayTableDataSource(
self.forecastArray,
{idAttribute: 'rep'}
);
I also have the requirement to add up the "total" attribute column and find the grand total, but I am not getting the way to refer the total values in a for loop and add them up.
I am not able to access the total value inside my JS file using a code like below, and rather it gives the length value of self.forecastArray.length as 0.
for(i=0; i<self.forecastArray.length; i++){
alert("total:- " + self.forecastArray[i].total);
}
Would be grateful if someone can give me an idea on this.