首页 > 解决方案 > 使用 ng-repeat 在 bootstrap corousel 中显示 9 个项目

问题描述

总共 20 张图片,我必须在每个滑块中显示 9 个项目,所以总共 3 个滑块。

我尝试了以下链接

引导轮播中的四个项目 Ng 重复?

<div class='greybg' ng-repeat="comment in location.comments"> 
          <div class="row">
    <div id="myCarousel{{location.comments[0]._id}}" class="carousel slide" data-ride="carousel">
    <div class="carousel-inner  multiple_pictures" >
    <div class="item" ng-class="{active:!$index}">
    <div class="row" >
    <div class="col-sm-4"  ng-repeat="images in comment.images.slice(0,9)">
    <img ng-src={{images.path}} alt="First slide"> <div class="gplabel">{{$index+1}}</div>
    </div>
    </div>  
    </div>
    <div class="item">
    <div class="row">
    <div class="col-sm-4"  ng-repeat="images in comment.images.slice(9,18)">
    <img ng-src={{images.path}} alt="First slide"> <div class="gplabel">{{$index+1+9}}</div>
    </div>
    </div>
    </div>
    <div class="item">
    <div class="row">
    <div class="col-sm-4"  ng-repeat="images in comment.images.slice(18,27)">
    <img ng-src={{images.path}} alt="First slide"> <div class="gplabel">{{$index+1+18}}</div>
    </div>
    </div>
    </div>
    <a ng-if="comment.images.length>1" class="left carousel-control" href="#myCarousel{{location.comments[0]._id}}" role="button"
    data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
    </a>
    <a ng-if="comment.images.length>1" class="right carousel-control" href="#myCarousel{{location.comments[0]._id}}" role="button"
    data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
    </a>
    </div>
    </div></div></div>

但是图像计数将是动态的,所以如果我有 50 张图像意味着我必须写 6 次。我如何根据图像计数动态执行此操作。

标签: javascriptjqueryhtmlangularjsbootstrap-carousel

解决方案


推荐阅读