问题
I have something like this:
<div ng-repeat="atma in abc">
<li ng-repeat="atma in abc.slice(0,3)"><span>{{$index+1}} - {{atma.weapon}} </span></li>
</div>
I wanted to slice these results at, each div repeat, each time being used the 3 items from index.
So I would start with the first div showing the weapons ranging from 1 to 3. The second one would have elements from 4 to 6. And so on.
Can I use $index or something like that on my slice?
Ps.: This question came from trying my best on this question here. I'm still having some trouble, but I made another question based on what I could do with slice.
回答1:
1st:
<div ng-repeat="atma in data">
<ul ng-if="$index % 3 == 0">
<li><span>{{data[$index]}} </span>
</li>
<li ng-if="$index+ 1 < data.length"><span>{{data[$index+1]}} </span>
</li>
<li ng-if="$index+ 2 < data.length"><span>{{data[$index+2]}} </span>
</li>
</ul>
</div>
2nd:
<div ng-repeat="atma in data">
<ul ng-if="$index % 3 == 0" ng-init="tmp = data.slice($index, $index + 3)">
<li ng-repeat="atma1 in tmp"><span>{{atma1}}</span>
</li>
</ul>
</div>
http://plnkr.co/edit/Uo1ROo549swNorzixTi3?p=preview
来源:https://stackoverflow.com/questions/27573488/slice-by-index-with-increment