2016-06-24 15 views
0

Ich bin neu in AngularJS und ich möchte maximalen Wert von JSON Antwort.Wie Höchstwert von JSON Antwort in angularjs

Meine JSON Antwort:

var json_response = [ 
    { 
    "division": "Development", 
    "divisionactualcount": "100", 
    "divisiontargetcount": "10" 
    }, 
    { 
    "division": "QA", 
    "divisionactualcount": "200", 
    "divisiontargetcount": "1" 
    } 
] 

I Maximalwert

var maxCount = {{maximum value of divisionactualcount}}; 
+0

http://stackoverflow.com/questions/4020796/finding-the-max-value-of-an-attribute-in-an-array-of-objects – Alexander

+0

'Math.max.apply (Math, json_response. map (function (o) {return o.divisionactualcount;})) ' – Rakeschand

+0

In Bezug auf Dringlichkeitsanfragen [bitte lesen Sie dies] (http://meta.stackoverflow.com/q/326569/472495). – halfer

Antwort

0

https://plnkr.co/edit/tNhLmfpjd8xw7HZbvSSJ?p=preview

$scope.maxvalue=json_response[0].divisionactualcount; 

    for(var i=0;i<(json_response.length)-1;i++){ 
     if((parseInt(json_response[i].divisionactualcount)) < (parseInt(json_response[i+1].divisionactualcount))&&(parseInt(json_response[i+1].divisionactualcount)) > $scope.maxvalue){ 
     $scope.maxvalue=json_response[i+1].divisionactualcount; 
     } 
    } 

Dies kann eine Lösung für Ihre Frage festlegen möchten ..

0
$scope.maxx = 0; 
for(var x in json_response){ 
    if(json_response[x].divisionactualcount > $scope.maxx){ 
     $scope.maxx = json_response[x].divisionactualcount; 
    } 
} 
alert($scope.maxx); 

maxx geben Sie den maximalen Wert von von json_response.

Grüße.