Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
GetTotal returns strange result?
Message
 
 
À
Tous
Information générale
Forum:
Javascript
Catégorie:
Autre
Titre:
GetTotal returns strange result?
Divers
Thread ID:
01629281
Message ID:
01629281
Vues:
30
Hi everybody,

Wondering what is wrong here - I think I used similar code before just fine.

I have a scope function like this
$scope.getTotal = function (data, col) {
                    window.console && console.log('Getting total for transactions');
                    if (data && data.length > 0)
                        return data.reduce(function (a, b) { return a + b[col]; }, 0);
                    else
                        return 0;
                };
and it's called like this
$scope.invoiceTransactionsObject.filteredTotal = $scope.getTotal($scope.filteredTransactions, 'extension');
I expect the above to return just one number but instead I see all the numbers in a string and as a result I do not see the total in the screen.

Of course, I can re-write the above to just use a loop (and this is what I'll do), but wondering what is wrong with the current implementation.

UPDATE. Looking closer after re-writing the method, I see that all columns in the object are of character type, that's why my function didn't work. Someone probably changed the object to return all columns as character values. I'll take a closer look in API now.

UPDATE 2. I left the loop solution, but the problem was that developer returned everything converted to a string. I removed that and now everything works fine. I fixed the searches too.
If it's not broken, fix it until it is.


My Blog
Répondre
Fil
Voir

Click here to load this message in the networking platform