Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to add up values inside an observableArray?

User645883-OracleMar 20 2017 — edited Mar 21 2017

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.

This post has been answered by Hugh Zhang-Oracle on Mar 21 2017
Jump to Answer
Comments
Post Details
Added on Mar 20 2017
11 comments
1,303 views