我有一个对象数组如下。
$scope.students = [{'isSelected': true},
{'isSelected': true},
{'isSelected': false},
{'isSelected': true},
{'isSelected': true},
]
如何获得isSelected属性设置为的计数项目true?
更新:
问题是$scope.students从 REST api 获取,并且简单地循环遍历 $scope.students 变量undefined在请求完成之前不起作用,因为该变量在请求完成之前,因此循环代码出错说$scope.students is not defined.
我尝试使用,$watch但在那种情况下,我必须在 watch 指令下定义循环,并且它只在定义 $scope.students 时工作一次,之后循环不起作用,因为 $scope.students 本身没有改变。