角度ng重复与组项目的总和

时间:2015-07-17 14:00:39

标签: javascript ng-repeat angularjs-filter

我想要组(国家/地区)以及组合元素之和eq。 TA + TA = 150.在Jan标记的列中。我的plunker是http://plnkr.co/edit/Wwx3vUvhmpP8XgQJGXm2?p=preview

提前致谢...

$scope.months =  [ 
    { "mon" : "jan", "country" : "UK", "TA" : 70, "TSR" : 5164, "TP" : 2822 , "TR" : 10771},
    { "mon" : "feb", "country" : "UK", "TA" : 660, "TSR" : 6164, "TP" : 4822 , "TR" : 10771},
    { "mon" : "mar", "country" : "UK", "TA" : 57, "TSR" : 1164, "TP" : 3322 , "TR" : 20771},

    { "mon" : "jan", "country" : "Austria", "TA" : 80, "TSR" : 5164, "TP" : 2822 , "TR" : 10771},
    { "mon" : "feb", "country" : "Austria", "TA" : 67, "TSR" : 6164, "TP" : 4822 , "TR" : 10771},
    { "mon" : "mar", "country" : "Austria", "TA" : 55, "TSR" : 1164, "TP" : 3322 , "TR" : 20771}
    ];

我的HTML是:

<table>
  <thead>
    <tr>
      <td>Jan</td>
      <td>Feb</td>
      <td>Mar</td>
    </tr>
  </thead>
  <tr>
    <td ng-repeat="month in months" >
      <table >
        <tr>
          <td>{{month.TA}}</td>                                                
        </tr>
        <tr>
          <td>{{ month.TSR }}</td>                                               
        </tr>                      
      </table>
    </td>
  </tr>
</table>

1 个答案:

答案 0 :(得分:0)

我认为你可以做这样的事情

$scope.GetSummOfAges=function(group){
  var summ=0;
  for(var i in group.data)
  {
    summ=summ+Number(group.data[i].age);
  }
  return summ;
};