我正在尝试建立分页使用Bootstrap pager在我的angularjs代码,但下一步按钮总是看起来是disabled.When,我运行相同的代码与常量数据,它是工作的fine.In控制器,我正在获取数据显示通过Rest API和数据是从API返回。
<div ng-app="manageApp">
<div ng-controller="ManageCampaignController" class="bs-example">
<div>
<div class="btn-group inline-content">
<label class="btn btn-primary" ng-model="existingCampaigns.manageMode" btn-radio="'Current'">Current</label>
<label class="btn btn-primary" ng-model="existingCampaigns.manageMode" btn-radio="'Other'" >Other</label>
</div>
</div>
<div ng-show="existingCampaigns.manageMode=='Current'">
{{totalItems}}{{currentPage}}
<pager total-items="3" ng-model="currentPage"></pager>
<table class="table" style="width:800px;">
<thead class="row">
<th class="col-md-1">
Name
</th>
<th class="col-md-1">
Start Date
</th>
<th class="col-md-1">
End Date
</th>
<th class="col-md-1">
Status
</th>
<th class="col-md-3">
Actions
</th>
</thead>
<tbody>
<tr ng-repeat= "item in existingCampaigns | limitTo:1">
<td>
{{item.name}}
</td>
<td>
{{item.startDate}}
</td>
<td>
{{item.endDate}}
</td>
<td>
{{item.status}}
</td>
<td>
<input class="btn btn-default" type="button" value="View"/>
<input class="btn btn-default" type="button" value="Edit"/>
<input class="btn btn-default" type="button" value="Pause"/>
<input class="btn btn-default" type="button" value="Archive"/>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
var manageApp = angular.module('manageApp',['ngAnimate', 'ui.bootstrap']);
manageApp.controller('ManageCampaignController', function($scope, $http, $log) {
$scope.currentPage = 1;
$scope.existingCampaigns = {};
$http.get('http://localhost:8080/campaign_manager/campaign').success(function (data){
$log.log('data' + data);
$scope.existingCampaigns = data;
$scope.totalItems = $scope.existingCampaigns.length;
$log.log('totalItems' + $scope.totalItems);
$scope.setPage = function (pageNo) {
$scope.currentPage = pageNo;
};
$scope.pageChanged = function() {
$log.log('Page changed to: ' + $scope.currentPage);
};
});
});
manageApp.filter('startFrom', function() {
return function(input, start) {
if (!input || !input.length) { return; }
start = +start; //parse to int
return input.slice(start);
}
});发布于 2015-08-24 16:55:58
我不确定这是不是你想要的,但是要寻呼引导,你可以使用下面这样的东西。它可能运行得更好:
html:
<pagination page="currentPage" max-size="nbOfPages" total-items="totalItems" items-per-page="nbItemsPerPage"></pagination>控制器:
$scope.currentPage = 1;
$scope.existingCampaigns = {};
$http.get('http://localhost:8080/campaign_manager/campaign').success(function (data){
$log.log('data' + data);
$scope.existingCampaigns = data;
//pagination
$scope.totalItems = $scope.existingCampaigns.length;
$scope.nbItemsPerPage = 2; //You can modify this value like you want
$scope.nbOfPages = Math.ceil($scope.totalItems / $scope.numPerPage);
$log.log('totalItems' + $scope.totalItems);
$scope.setPage = function (pageNo) {
$scope.currentPage = pageNo;
};如果这对你有帮助,请随时通知我。附言:如果你可以,创建一个管道,这将更容易帮助你。
发布于 2015-08-25 14:52:16
我通过myself.Thing发现我需要使用Bootstrap的每页项目数属性。
<pagination ng-model="currentPage" total-items="total" items-per-page="numPerPage"></pagination>https://stackoverflow.com/questions/32175543
复制相似问题