How to generate a different total per row?

0

I have the following code:

 <td ng-repeat="actividad in actividades | filter:{circular_id: puntuacion.circular_id, tipo_a_id: 1}">
    <span ng-repeat="puntuacion in puntuaciones | filter:{club_id: club.id, 
    actividad_id: actividad.id}" ng-bind="puntuacion.puntos || 0" ng-
    init="total(puntuacion, club)"></span>
 </td>

With ng-init="total(puntuacion, club)" , I want to generate the total points per row, that is, per club.

The total function is as follows:

$scope.total = function(puntuacion, club){
  if(puntuacion.club_id == club.id){
     $scope.total[club.id] += (puntuacion.puntos);
  }
}

This function generates me is the last value that each club has and not the sum of each one of them.

Look at the result:

Please, I thank you in advance for your help!

    
asked by Ziul̺̿i̺̿n̺̿g̺̿ Maca̶yo 31.08.2017 в 00:16
source

1 answer

0

I understand that you mean that each row is a different club, right? I think the problem is that you keep the total of the scores in the same variable for all and each row / club should have its own counter.

One possible solution would be to pass one more parameter ( $index ) to the total function, something like this:

<td ng-repeat="actividad in actividades | filter:{circular_id: puntuacion.circular_id, tipo_a_id: 1}" ng-init="teamIndex = $index">
    <span ng-repeat="puntuacion in puntuaciones | filter:{club_id: club.id, 
    actividad_id: actividad.id}" ng-bind="puntuacion.puntos || 0" ng-
    init="total(puntuacion, teamIndex)"></span>
 </td>
$scope.total = function(puntuacion, indice){
  if(puntuacion){
    $scope.total[indice] += (puntuacion.puntos);
  }
}
    
answered by 31.08.2017 в 09:29