2015-04-05 82 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