【问题标题】:row number for each table row created by dir-paginate angularJs由 dir-paginate angularJs 创建的每个表行的行号
【发布时间】:2016-09-02 06:38:49
【问题描述】:

如何为 dir-paginate angularJs 创建的每个表行设置行号。 我使用双向代码,但两种方式不正确并设置错误。

第一种方式:

    <tr dir-paginate='customer in Customers| itemsPerPage: 10'>
        <td>{{rowNum=(rowNum+1)}}</td>
        <td>{{customer.fName}}</td>
        <td>{{customer.lName}}</td>
    </tr>

<script>
 (function(){
    var app = angular.module('customerApp', ['angularUtils.directives.dirPagination']);
    app.controller('customer', ['$scope', '$http',  function($scope, $http){
        $scope.rowNum = 1;
   }]);
})();
</script>

第二种方式:

<tr dir-paginate='customer in Customers| itemsPerPage: 10'>
        <td>{{getRowNum()}}</td>
        <td>{{customer.fName}}</td>
        <td>{{customer.lName}}</td>
    </tr>

<script>
 (function(){
    var app = angular.module('customerApp', ['angularUtils.directives.dirPagination']);
    app.controller('customer', ['$scope', '$http',  function($scope, $http){
        $scope.rowNum = 1;
        $scope.getRowNum = function(){
            return ++$scope.rowNum;
        };
   }]);
})();
</script>

为什么我不能从函数和 ng-bind 中增加 $scope.rowNum

【问题讨论】:

  • 你能给我们提供一个codepen oder fiddlejs示例吗?

标签: javascript angularjs dirpagination


【解决方案1】:

我认为 {{$index+1}} 应该可以工作

带有索引 + 分页的图像 -> {{(currentPage-1)*pageSize +$index+1}}

【讨论】:

  • 我之前测试过这段代码,但页面更改时会重置数字。但我希望当页面为 2 时,行号从上一页继续。
  • 好的,如果你使用 currentPage 和 pageSize 像 dir-pagination 的演示,你也可以用 {{(currentPage-1)*pageSize +$index+1}}
  • $scope.currentPage = 1; $scope.pageSize = 10;
  • 我刚刚将它添加到plnkr.co/edit/Wtkv71LIqUR4OhzhgpqL?p=preview 并且它有效。你定义了 $scope.currentPage 和 $scope.pageSize 吗?
  • 我对其进行了测试,但是当页面更改编号行从 1 开始时。但是如果页面有 2 行号,我想继续这个数字,如果 perPage 10 应该是 11
  • 我在原始答案中添加了一张图片。如果你定义了 $scope.pageSize 和 $scope.currentPage,我不明白你为什么会得到 NaN。您还可以看到 {{(currentPage-1)*pageSize +$index+1}} 应该与您提到的分页一起使用。另一种意见是通过循环添加索引。
  • 猜你喜欢
    相关资源
    最近更新 更多
    热门标签