试图使用AngularJS UI引导分页指令在一个小型搜索应用程序上完成分页。几乎有它的工作,除了我不能得到前10个结果显示后,最初的搜索。
所发生的情况是,最初的100个结果被加载,它们被分割成每页显示10个。但是,在分页部分并单击分页控件中的页"1“链接后,才会出现前10页。
这是HTML
<uib-pagination total-items="results.totalItems" max-size="10" items-per-page="itemsPerPage" ng-model="currentPage" ng-change="changePage()" direction-links="true" previous-text="‹" next-text="›" class="pagination-sm"></uib-pagination>这是我的搜索函数,它加载初始的100个结果
$scope.search = function() {
$scope.isSearching = true;
return searchService.search($scope.searchTerms, $scope.currentPage).then(function(es_return) {
var totalItems = es_return.hits.total;
var totalTime = es_return.took;
var numPages = Math.ceil(es_return.hits.total / $scope.itemsPerPage);
$scope.results.pagination = [];
for (var i = 1; i <= 100; i++) {
if(totalItems > 0)
$scope.results.totalItems = totalItems;
$scope.results.queryTime = totalTime;
$scope.results.pagination = searchService.formatResults(es_return.hits.hits);
}
}
)
};这些是我用来分页的函数
$scope.paginate = function() {
var begin = (($scope.currentPage - 1) * $scope.itemsPerPage);
var end = begin + $scope.itemsPerPage;
$scope.results.documents = $scope.results.pagination.slice(begin, end);
};
$scope.changePage = function() {
$scope.paginate();
};我很确定这个问题的罪魁祸首是$scope.search()中的这一行
$scope.results.pagination "=" searchService.formatResults(es_return.hits.hits);特别是等号?
我还在学习js和angularjs,所以我不确定应该用什么来代替"=" .以使最初的10个结果出现
发布于 2016-07-02 18:06:01
$scope.results.documents似乎是保存当前显示的文档的属性。您还需要在searchService返回其结果后设置它,而不仅仅是在单击分页时。
$scope.results.pagination是完整的结果数组,所以您希望像更改页面时那样对其进行切片。
发布于 2016-07-02 18:07:27
变化
`) };` 转到).then((){$scope.paginate();}); }
所以你可以肯定,分页是在你准备好之后发生的。
https://stackoverflow.com/questions/38162948
复制相似问题