我想在每周基础上迭代对象。假设有31天,我需要每周显示这31个日期。我尝试使用limitTo: 7
,但不幸的是它没有用。在我试过的代码下面。
我希望每7个对象都需要重复div
类class="accordian-section"
。即第一个7是1 <div>
。对于接下来的7个对象,同样需要重复。
<div class="accordian-section" data-ng-repeat="data in vm.dailyUsageList track by $index | limitTo: 7:7">
<a id="analysisWeek1-title" href="#analysisWeek-1" role="button" data-toggle="collapse" area-controls="analysisWeek-1">Week 1 <span class=""></span></a>
<ul id="analysisWeek-1" area-labelledby="analysisWeek1-title" class="row position-relative panel-collapse collapse">
<span class="sprite arrow grey-arrow"></span>
<li><span class="col-xs-14 padding0">{{data.date | date:'dd MMM yyyy'}}</span><span class="col-xs-2 padding0 text-align-right">{{data.usage}}MB</span></li>
<li><span class="col-xs-14 padding0">{{data.date | date:'dd MMM yyyy'}}</span><span class="col-xs-2 padding0 text-align-right">{{data.usage}}MB</span></li>
<li><span class="col-xs-14 padding0">{{data.date | date:'dd MMM yyyy'}}</span><span class="col-xs-2 padding0 text-align-right">{{data.usage}}MB</span></li>
<li><span class="col-xs-14 padding0">{{data.date | date:'dd MMM yyyy'}}</span><span class="col-xs-2 padding0 text-align-right">{{data.usage}}MB</span></li>
<li><span class="col-xs-14 padding0">{{data.date | date:'dd MMM yyyy'}}</span><span class="col-xs-2 padding0 text-align-right">{{data.usage}}MB</span></li>
<li><span class="col-xs-14 padding0">{{data.date | date:'dd MMM yyyy'}}</span><span class="col-xs-2 padding0 text-align-right">{{data.usage}}MB</span></li>
<li><span class="col-xs-14 padding0">{{data.date | date:'dd MMM yyyy'}}</span><span class="col-xs-2 padding0 text-align-right">{{data.usage}}MB</span></li>
</ul>
</div>
答案 0 :(得分:1)
将单维数组转换为多维数组。并迭代Fiddle
function MyCtrl($scope) {
$scope.ArraySplit = function(array, chunk) {
var temparray = [];
for (i = 0, j = array.length; i < j; i += chunk) {
temparray.push(array.slice(i, i + chunk));
}
return temparray;
}
$scope.arrayList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31];
$scope.newList = $scope.ArraySplit($scope.arrayList, 7)
}