2015-04-05 65 views
1

我有一個數組,這是我使用的推送方法:如何訪問對象陣列中angularjs

  for(var j=0; j<$scope.currentUsers.length; j++){ 
      $scope.Users.push({user_id:$scope.currentUsers[j].user_id, student_name:$scope.currentUsers[j].student_name, 
       "A":[{"color":"white"}, {count:0}], 
       "E":[{"color":"white"}, {count:0}], 
       "J":[{"color":"white"}, {count:0}] 
      }); 

     } 

我想知道如何我可以訪問到的計數中A,E或J〜

I tried $scope.Users[i].A.count 

I tried $scope.Users[i][A][count]

他們都showd我 「南」 或不確定。難道我做錯了什麼?

在此先感謝您的幫助!

回答

3

「A」字段是一個數組。所以,代碼的右邊部分是:

$scope.Users[i].A[1].count 

否則,聲明每個字段 「A」 的, 「E」, 「J」 作爲JSON與對象:

"A":{"color":"white", count:0}, 
"E":{"color":"white", count:0}, 
"J":{"color":"white", count:0} 

並與訪問它們:

$scope.Users[i].A.count 
+0

謝謝!現在很清楚! – Lisa 2015-04-05 23:35:13