我有一个Angular Repeater,它显示了我下面的JSON数组的结果。现在只有今天的物品才具有价值:' vandaag = true'。
16: {id: "55", datum: "2015-08-17", punt: "dsfga", tellen: 2,…}
datum: "2015-08-17"
id: "55"
punt: "dsfga"
tellen: 2
vandaag: false
17: {id: "63", datum: "2015-08-18", punt: "lkjsdfg", tellen: 1,…}
datum: "2015-08-18"
id: "63"
punt: "lkjsdfg"
tellen: 1
vandaag: true
在我的中继器中,我给了今天的课程.vandaag:
<div ng-repeat="r in results | filter:dateFilter" class="relatief" ng-class="{vandaag: r.vandaag === true}">
CSS以正确的方式理解这一点,但JQuery并不是这样。我常常按班来统计项目,但是当我上课时,似乎不存在。因为现在它返回0:
$http.post('../ajax_crud.php', {positief: 'get', userId: userId, datumText: datumText}).
success(function (data, status, headers, config) {
$scope.results = data;
var vandaag = $('.vandaag').length;
console.log(vandaag);
});
所以我的问题是:如何以正确的方式计算类.vandaag的项目?
答案 0 :(得分:1)
您只需计算过滤结果,如下所示:
<!--Assign the filtered list to a new var called "filtered"-->
<div ng-repeat="r in filtered = (results | filter:dateFilter)" class="relatief" ng-class="{vandaag: r.vandaag === true}">
//Access new "filtered" var
var vandaag = $scope.filtered.filter(function(r) {
return r.vandaag === true;
}).length;