Javascript 在数组中每隔x个元素插入新行
我有这样一个标记:Javascript 在数组中每隔x个元素插入新行,javascript,angularjs,Javascript,Angularjs,我有这样一个标记: <div class="row"> <div class="col col-50" ng-repeat="picture in pictures.slice().reverse()"> <a href="instagram://media?id={{picture.id}}" title="{{picture.caption.text}}" target="_blank"> <img n
<div class="row">
<div class="col col-50" ng-repeat="picture in pictures.slice().reverse()">
<a href="instagram://media?id={{picture.id}}" title="{{picture.caption.text}}" target="_blank">
<img ng-src="{{picture.images.standard_resolution.url}}" width="100%" height="auto" alt="{{picture.caption.text}}" />
</a>
</div>
</div>
除了使用Javascript手动执行输出之外,我真的不知道如何执行。我一直在看文件,但我找不到办法。有人能给我提些建议吗,或者给我指出正确的方向吗?只要您的图片数组长度相等,使用ng开关应该可以工作
<div class="row" ng-repeat="picture in pictures.slice().reverse()" ng-switch on="$index % 2" ng-show="$index%2==1">
<div class="col col-50" ng-switch-when="1">
<a href="instagram://media?id={{pictures[$index-1].id}}" title="{{pictures[$index-1].caption.text}}" target="_blank">
<img ng-src="{{pictures[$index-1].images.standard_resolution.url}}" width="100%" height="auto" alt="{{pictures[$index-1].caption.text}}" />
</a>
</div>
<div class="col col-50" ng-switch-when="1">
<a href="instagram://media?id={{picture.id}}" title="{{picture.caption.text}}" target="_blank">
<img ng-src="{{picture.images.standard_resolution.url}}" width="100%" height="auto" alt="{{picture.caption.text}}" />
</a>
</div>
</div>
这在小提琴中如何工作的简单示例:
我的第一个回答可能与angular的所有版本都不兼容,请现在查看。
<div class="row" ng-repeat="picture in pictures.slice().reverse()" ng-switch on="$index % 2" ng-show="$index%2==1">
<div class="col col-50" ng-switch-when="1">
<a href="instagram://media?id={{pictures[$index-1].id}}" title="{{pictures[$index-1].caption.text}}" target="_blank">
<img ng-src="{{pictures[$index-1].images.standard_resolution.url}}" width="100%" height="auto" alt="{{pictures[$index-1].caption.text}}" />
</a>
</div>
<div class="col col-50" ng-switch-when="1">
<a href="instagram://media?id={{picture.id}}" title="{{picture.caption.text}}" target="_blank">
<img ng-src="{{picture.images.standard_resolution.url}}" width="100%" height="auto" alt="{{picture.caption.text}}" />
</a>
</div>
</div>