我在表格下方有一个 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/