嘗試使用AngularJS UI bootstrap pagination directive在小型搜索應用上完成分頁。幾乎有它的工作除了我不能得到前10個搜索結果後顯示。AngularJS分頁幾乎工作
會發生什麼情況是加載了最初的100個結果,並且它們被拆分爲每頁顯示10個結果。但是,在分頁之後,前10個字段不會出現,然後單擊分頁控件中的頁面「1」鏈接。
這是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個結果顯示
感謝您的簡單回答,我正在反思這一點 - 一行簡單的代碼,它的工作原理! – user3125823