在我的新项目中,名为"黄金贷款管理系统",我需要使用指定的GLID从装饰表中获取装饰品名称.GLID不是唯一的,所以我们可能有多行相同的GLID和装饰名称。ornament name with weight
现在我想在执行ng-if.I used" {{ornamentdata.length}}"之后计算装饰品的数量。在装饰品表中得到装饰品的总数。如何才能找到因ng-if而得到的装饰品总数?
的index.html
<table class="table table-bordered table-hover">
<tr ng-repeat="ornament in ornamentdata" ng-if="ornament.GLID == cstmrdetails.GLID">
<td>{{$index }}</td>
<td>{{ornament.ORNAMENT}}</td>
<td>{{ornament.WEIGHT}}gm</td>
</tr>
</table >
答案 0 :(得分:3)
答案 1 :(得分:1)
首先将类添加到ng-repeat raw,然后创建另一个raw并调用一个函数。从那里得到行的长度
<table class="table table-bordered table-hover">
<tr ng-repeat="ornament in ornamentdata" ng-if="ornament.GLID == cstmrdetails.GLID" class="row-count">
<td>{{$index }}</td>
<td>{{ornament.ORNAMENT}}</td>
<td>{{ornament.WEIGHT}}gm</td>
</tr>
<tr ng-init="getCount()">
<td> count{{count }}</td>
</tr>
</table >
$scope.getCount = function(){
$timeout(function(){
$scope.count = document.getElementsByClassName('row-count').length;
});
}
答案 2 :(得分:0)
制作名为filterWithCondition
在你的Html中
<table class="table table-bordered table-hover">
<tr ng-repeat="ornament in filteredData = (ornamentdata | filterWithCondition:'GLID':cstmrdetails.GLID)">
<td>{{$index }}</td>
<td>{{ornament.ORNAMENT}}</td>
<td>{{ornament.WEIGHT}}gm</td>
</tr>
Filtered Data Count is {{filteredData.length}}
</table >
过滤器如下所示
app.filter('filterWithCondition', function() {
return function(items, itemKey, compareWith) {
var filtered = items.filter(function(item){
return item.itemKey == compareWith
})
return filtered;
}
});
plnkr demo Filter Demo