我正在重复这样的 JSON 对象(嵌套)项目列表:
<div ng-repeat='item in items'>
<ul>
<li ng-repeat='specific in item'>{{specific}}</li>
</ul>
</div>
我想在页面顶部的每个项目对象中显示“特定”项目的数量(在 ng-repeat 范围之外)。我无法使用 items.length,因为我想显示特定项目的数量(必须如此循环),但我不知道如何绑定(bind) ng-repeat 中的数据并在其范围之外使用它..
最佳答案
<span>Number of items : {{countItems(items.length)}}</span>
$scope.countItems = function(items) {
var count = 0;
for(var item in items) {
for(var specific in item) {
count++;
}
// Instead of the second for, you can just write :
// count = count + item.length;
}
return count;
};
应该可以解决问题:)
关于javascript - 显示超出其范围的 ng-repeat 项目数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35476273/