页面展示效果:
页面HTML代码:
<table class="table table-striped" style="margin: 0px;">
<thead>
<tr>
<td>选择</td>
<td>企业名称</td>
<td>企业地址</td>
<td>状态</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="l in list">
<td><input type="radio" name="id" ng-click="select(l.id)" value="{{l.id}}" /></td>
<td>{{l.name}}</td>
<td>{{l.address}}</td>
<td>{{l.status_str}}</td>
</tr>
</tbody>
</table>
<!-- paging -->
<ul class="pagination" style="margin: 0px;" >
<li ng-class="{true:'disabled'}[p_current==1]"><a href="javascript:void(0);" ng-click="p_index()">首页</a></li>
<li ng-repeat="page in pages" ng-class="{true:'active'}[p_current==page]"><a href="javascript:void(0);" ng-click="load_page(page)">{{ page }}</a></li>
<li ng-class="{true:'disabled'}[p_current==p_all_page]"><a href="javascript:void(0);" ng-click="p_last()">尾页</a></li>
</ul>
<span style="vertical-align: 12px;"> 共:{{count}} 条</span>var app = angular.module("myApp",[]);
app.controller("map_ctrl",function($scope,$http,$location){
//配置
$scope.count = 0;
$scope.p_pernum = 10;
//变量
$scope.p_current = 1;
$scope.p_all_page =0;
$scope.pages = [];
//初始化第一页
_get($scope.p_current,$scope.p_pernum,function(){
alert("我是第一次加载");
});
//获取数据
var _get = function(page,size,callback){
$http.get("xxx.html?status=0&page="+page+"&size="+size).success(function(res){
if(res&&res.status==1){
$scope.count=res.count;
$scope.list=res.list;
$scope.p_current = page;
$scope.p_all_page =Math.ceil($scope.count/$scope.p_pernum);
reloadPno();
callback();
}else{
alert("加载失败");
}
});
}
//单选按钮选中
$scope.select= function(id){
alert(id);
}
//首页
$scope.p_index = function(){
$scope.load_page(1);
}
//尾页
$scope.p_last = function(){
$scope.load_page($scope.p_all_page);
}
//加载某一页
$scope.load_page = function(page){
_get(page,$scope.p_pernum,function(){ });
};
//初始化页码
var reloadPno = function(){
//分页算法
for(var i = 1; i <= $scope.p_all_page; i++) {
if(i == 2 && $scope.p_current - 6 > 1) {
i = $scope.p_current - 6;
}else if(i == $scope.p_current + 6 && $scope.p_current + 6 < $scope.p_all_page) {
i = $scope.p_all_page - 1;
}else{
$scope.pages.push(i);
}
}
};
});
分页算法:
var paging = function(current,allpage){
var html ="";
//分页算法
for(var i = 1; i <= allpage; i++) {
if(i == 2 && current - 6 > 1) {
i = current - 6;
}else if(i == current + 6 && current + 6 < allpage) {
i = allpage - 1;
}else{
if(current==i){
//表示选中该页
html+="<li class='active'><a href='xxx.html?p="+i+"'>"+i+"</a></li>";
}else{
//未选中该页
html+="<li><a href='xxx.html?p="+i+"'>"+i+"</a></li>";
}
}
}
return html;
};
原创:http://blog.csdn.net/qilin001cs
原文:http://blog.csdn.net/qilin001cs/article/details/51364063