2014-09-30 1 views
0

Я получил JSON:Выходное значение реферирования с Angular.JS и нг-таблицы

var scholars = [{"FirstName":"John","LastName":"Doe","Unit":"PA","Institution":"University of Haifa","teken":1,"FirstYearActive":"2007","hIndex":"3","j2014":0,"j2013":4,"j2012":3,"j2011":0,"j2010":0,"j20052009":2,"j20002004":0,"j19901999":0,"jPriorto1990":0,"ab2014":0,"ab2013":0,"ab2012":0,"ab2011":0,"ab2010":0,"ab20052009":0,"ab20002004":0,"ab19902000":0,"abPriorto1990":0,"c2014":5,"c2013":10,"c2012":7,"c2011":0,"c2010":3,"c20052009":2,"c20002004":0,"c19901999":0,"cPriorto1990":0,"b2014":0,"b2013":0,"b2012":0,"b2011":0,"b2010":0,"b20052009":0,"b20002004":0,"b19902000":0,"bPriorto1990":0,"YearsActive":"8","HIE":"72.9"}, 
{"FirstName":"John","LastNAme":"Smith","Unit":"G&PT","Institution":"University of Haifa","teken":1,"FirstYearActive":"1996","hIndex":"3","j2014":0,"j2013":0,"j2012":0,"j2011":0,"j2010":0,"j20052009":1,"j20002004":2,"j19901999":2,"jPriorto1990":0,"ab2014":0,"ab2013":0,"ab2012":0,"ab2011":0,"ab2010":0,"ab20052009":0,"ab20002004":0,"ab19902000":0,"abPriorto1990":0,"c2014":3,"c2013":1,"c2012":3,"c2011":5,"c2010":3,"c20052009":2,"c20002004":0,"c19901999":0,"cPriorto1990":0,"b2014":0,"b2013":0,"b2012":0,"b2011":0,"b2010":0,"b20052009":0,"b20002004":0,"b19902000":0,"bPriorto1990":0,"YearsActive":"19","HIE":"25.5"}, 
{"FirstName":"John","LastName":"Guitar","Unit":"IR","Institution":"University of Haifa","teken":1,"FirstYearActive":"2009","hIndex":"0","j2014":0,"j2013":0,"j2012":0,"j2011":0,"j2010":0,"j20052009":1,"j20002004":0,"j19901999":0,"jPriorto1990":0,"ab2014":0,"ab2013":0,"ab2012":0,"ab2011":0,"ab2010":0,"ab20052009":0,"ab20002004":0,"ab19902000":0,"abPriorto1990":0,"c2014":0,"c2013":0,"c2012":0,"c2011":0,"c2010":0,"c20052009":0,"c20002004":0,"c19901999":0,"cPriorto1990":0,"b2014":0,"b2013":0,"b2012":0,"b2011":0,"b2010":0,"b20052009":0,"b20002004":0,"b19902000":0,"bPriorto1990":0,"YearsActive":"6","HIE":"0"}] 

И мне нужно суммировать все j2014 «s с этим кодом:

var j14sum = 0; 
     for (var i in scholars){ 
     if (scholars[i].Institution == "University of Haifa") 
      j14sum += parseInt(scholars[i].j2014); 
     }; 

Теперь, как я работаю с angular.js и выводя результаты с помощью ng-table?

Большое спасибо!

+0

Вы хотите напечатать сумму J14 для все различного учреждения? – rllola

+0

Да, что я хочу – alik

+0

А также для остальной части «j» s (j2013, j2012 ...) – alik

ответ

0

Хорошо, я понял, как решить проблему.

var reduced = scholars.reduce(function(map,obj){ 
    if(!(obj.Institution in map)){ 
     map[obj.Institution] = { 
      Institution:obj.Institution, 
      j2014: 0 
     }; 
    } 
    map[obj.Institution].j2014 += parseInt(obj.j2014); 
    return map; 
},{}); 

Вот скрипка: http://jsfiddle.net/axdg1r4t/4/