javascript - Angular Dir-Pagination 并调用 Controller 功能

标签 javascript angularjs pagination

我在表格下方有一个 Angular html 片段,我正在尝试使用 Dir-Paginate 连接。并且还有基于controller.js上的函数的表行更改类

<tr dir-pagination="response in vm.responses  | toArray | orderBy:'-completionTime' | itemsPerPage: $root.pagination.itemsPerPage" class="{{ vm.getRowClass($index) }}">
    <td> {{ $index + 1 }}</td>
    <td><a ui-sref="response({uri:response.uri})">{{ response.name }}</a></td>
    <td><a href="mailto:{{ response.email }}">{{ response.email }}</a></td>
 <tr>

<dir-pagination-controls ng-show="appvm.showDataTable()" boundary-links="true" on-page-change="pageChangeHandler(newPageNumber)" template-url="ng/pagination"></dir-pagination-controls>

如果我删除所有 Dir-Pagination 语法并使其成为正常的 ng-repeat vm.getRowClass($index)正常工作,根据函数的逻辑更改类。但是,当我尝试添加 dir-pagination 语法时,我得到了 $Index is undefined错误。

问题似乎是 Dir-Paginate 不允许我传递 $index或与 <tr> 同一行的任何项目

最佳答案

经过评论和一番尝试后,我找到了解决方案。

我需要将 track by $index 添加到 itemsPerPage: $root.pagination.itemsPerPage 区域的末尾。

下面正确显示。

<tr dir-pagination="response in vm.responses  | toArray | orderBy:'-completionTime' | itemsPerPage: $root.pagination.itemsPerPage track by $index" class="{{ vm.getRowClass($index) }}">
    <td> {{ $index + 1 }}</td>
    <td><a ui-sref="response({uri:response.uri})">{{ response.name }}</a></td>
    <td><a href="mailto:{{ response.email }}">{{ response.email }}</a></td>
 <tr>

关于javascript - Angular Dir-Pagination 并调用 Controller 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31278209/

相关文章:

javascript - 如何使用 redux saga 将 ID 传递给 API 调用?

javascript - 输入和 dom 值存储在哪里?

javascript - 如何使 ng-click 在 Angular DataTables 列生成器中工作?

javascript - 在 AngularJS 动态表单中禁用文本框

php - PHP-MySQL 分页中的序列号

php - 行分页时如何检索列总数?

javascript - 滑动轮播 - 分页未指向正确的位置

javascript - AnguIarJS : how do I edit a single background image to have a different background size than the rest

javascript - Chart.js - 鼠标悬停导致图形闪烁和调整大小

javascript - 通过不同 Controller 的 $scopes 将索引推送到不同变量中