我正在构建一个评分系统,并试图根据单独集合中的值计算分数。我一直在使用这个例子:计算 AngularJS ng-repeat 中重复元素的总和,但由于我相信他们使用的是一个集合而不是两个集合,所以无法让它工作。
这是我使用上述问题中的建议的模板:
<div>{{parent.id}}</div>
<div>{{ getTotal() }}</div>
<div ng-repeat="child in children | orderBy: '-postedTime' | filter: {parentId: parent.id}">
<div>{{child.score}}</div>
</div>
js:
$scope.getTotal = function(){
var total = 0;
for(var i = 0; i < $scope.children.length; i++){
var score = $scope.child.score[i];
total += (child.score);
}
return total;
}
有没有办法将过滤后的孩子的所有分数相加并显示在父母身上?