angularjs - 如何以角度显示当前显示的条目范围
问题描述
这是我用来实现分页的:
<pagination total-items="reportCount" items-per-page="itemsPerPage" page="currentPage" ng-change="pageChanged()" ng-model="currentPage"></pagination>
我如何让它显示当前显示的条目范围.. 比如.. 1-10 of 46 entries
。11-20 of 46
等等..
我可以使用 的值currentPage
并itemsPerPage
通过执行以下操作来获得它:
<span id="page_info">Showing {{(currentPage-1) * itemsPerPage + 1}} - {{currentPage * itemsPerPage}} of {{reportCount}} entries</span>
但问题出在最后一页,最后一条记录不只是currentPage * itemsPerPage
.. 它显示41-50 of 46 entries
。
它应该与{{Math.min((currentPage * itemsPerPage), reportCount)
}} 一起使用,但由于某种原因它没有在这里评估它。
任何想法如何解决这个问题?或任何其他方式?
解决方案
当像, , ,等评估角度绑定时,浏览器对象模型(BOM
)将不直接可用。您可以在函数内部调用它们,但不能直接在内部绑定上调用它们(认为有办法通过保持该属性来做到这一点,我不建议这样做)。为了使其正常工作,为 a 内部创建一个 javascript 函数并在绑定级别调用它。Math
console
location
window
BOM
$scope
$scope
<span id="page_info">
Showing {{(currentPage-1) * itemsPerPage + 1}} - {{endCount(currentPage,itemsPerPage, reportCount)}} of {{reportCount}} entries
</span>
控制器
$scope.endCount = function (currentPage, itemsPerPage, reportCount) {
return Math.min((currentPage * itemsPerPage), reportCount);
}
推荐阅读
- biztalk - BizTalk 2013 WCF-SQL 适配器插入十进制 (38,20)
- react-native - Jest-expo 测试不运行
- create-react-app - 如果弹出后出现 lint 错误,则构建失败
- android - LiveData、MVVM 和存储库模式
- docusignapi - 如何在docusign php api的帮助下将html表格添加到DocuSign文档中?
- c++ - QTableWidget 到多个文件
- c++ - OpenGL着色器存储缓冲区/memoryBarrierBuffer
- c# - 如何将组合框绑定到 ObservableCollection 列表中的某个项目 - WPF?
- c++ - 从多个模板化基类派生时出现“隐藏重载的虚函数”警告
- reactjs - 为什么我应该使用 Ant Design 而不是其他前端库