Angularjs:如何在所有分页页面中将$ index保留在数据列表中

时间:2019-06-29 23:36:42

标签: javascript angularjs

在分页后如何保持 $ index 数字在列表数据中。

假设data.length 50 ,它们从索引0 开始,第一页包含 10 项,最后是索引9 ,第二页的下一项应从索引10 开始,依此类推。

<script type="text/ng-template" id="custom-pagination">
    <li ng-class="{disabled: noPrevious()||ngDisabled, previous: align}" 
        class="disabled previous">
        <a class="btn btn-secondary btn-md mr-2 text-white"
           ng-click="selectPage(page - 1, $event)">
           <i class="fa fa-angle-left pagination-left"></i>
        </a>
    </li>
    <li ng-class="{disabled: noNext()||ngDisabled, next: align}" class="disabled next">
        <a class="btn btn-primary btn-md btn-md text-white"
           ng-click="selectPage(page + 1, $event)">
          <i class="fa fa-angle-right pagination-right"></i>
        </a>
    </li>
</script>
<ul class="unstyled inbox-pagination">
    <li>
        <span>
            <%currentPage%>-
            <% numPages %> из
            <%data.length%>
        </span>
    </li>
    <pagination class="np-btn pagination-sm float-right pagination"
                uib-pager boundary-links="true" total-items="data.length"
                ng-model="currentPage" items-per-page="pageSize"
                template-url='custom-pagination'>
    </pagination>
</ul>

<tr ng-repeat="(key, item) in data | startFrom: (currentPage - 1) * pageSize | limitTo: pageSize" class="cp"
    ng-right-click="ShowContextMenu(key,item.unique_order_id)"
    context="context_menu">
</tr>
app.controller(
    'user.controller', 
    ['$scope', '$filter', '$timeout', '$compile', 'csrfToken', 'sendRequest', 'toastr',  
    function($scope, $filter, $timeout, $compile, csrfToken, sendRequest, toastr){

    $scope.pageSize = 1
    $scope.currentPage = 1

    // ......

}]).filter('startFrom', function() {
    return function(data, start) {
    // Some code goes right here ...
        return data.slice(start)
    }
});

1 个答案:

答案 0 :(得分:1)

我找到了一个解决方案,而不是直接从 $ index 获取项目,我可以通过检查哪个索引来获取任何项目的索引该项目本身确实存在。

HTML

append()

JS

countZeros()