$().pagination(总条数,配置项);

后端分页的跨页选择:

  思路:把浏览过的页整体保存为,整体拥有 curPage(当前页码)、allChoice(当前页是否全选)、selected当前页的某一列是否被选中这样结构化的数据,然后使用结构化的数据渲染新页面,当查看其他页时,做页码匹配然后做整体替换。(存在的问题:数据更新频率比较高的数据不适合)

//原数据
    "list":[{
"createTime":1481904000000,
"stockCode":"333333",
"investorCode":"grun1",
"investorName":"小明",
"rationName":"ration4",
"authStatus":"00",
"rationCode":"011"
},{
"createTime":1481904000000,
"stockCode":"333333",
"investorCode":"grun1",
"investorName":"小花",
"rationName":"ration4",
"authStatus":"00",
"rationCode":"011"
}]
//结构化数据是关键点
[
{
"curPage":12,
"allChoice":false,
"list":[{
"createTime":1481904000000,
"stockCode":"333333",
"investorCode":"grun1",
"investorName":"小明",
"rationName":"ration4",
"authStatus":"00",
"rationCode":"011",
"selected":true
},{
"createTime":1481904000000,
"stockCode":"333333",
"investorCode":"grun1",
"investorName":"小花",
"rationName":"ration4",
"authStatus":"00",
"rationCode":"011",
"selected":true
}]
}
]

写在分页的callback方法中的数据组装和替换的代码如下:

function callback(page_index, jq){
var formData=init.formData;
formData.begin=page_index*init.items_per_page+1;
formData.end=(page_index+1)*init.items_per_page;
$remote.post(init.action,formData,function(data){
try{
console.log(scope.saveList[page_index].list);
}catch(e){//未初始化过
//开始
var dataList = data.list;
var listLen = dataList.length;
//初始化
for(var i=0; i < listLen; i++){
dataList[i].selected = false;
}
scope.saveList[page_index] = {};
scope.saveList[page_index].choiceAllFlag = false;
scope.saveList[page_index].list = dataList;
scope.saveList[page_index].curPage = page_index;//当前页码
}
scope.curPage2 = page_index;//当前页码 //切页码
var saveLen = scope.saveList.length;
for(var i=0; i < saveLen; i++){
if(scope.saveList[i].curPage == page_index){
//用历史页面 替换新数据
scope[init.list] = scope.saveList[i];
}
}
scope[init.list].formData=formData;//切换页数时使用的相同参数
if(!scope.$$phase){
scope.$apply();
}
});

全选、单选js代码

    //单选
$scope.choiceOne = function(item) {
// $scope.placingObjItem = item;
item.selected = !item.selected;
for(var i=0; i < $scope.applyList.list.length; i++){
if(!$scope.applyList.list[i].selected){//有未选中
var hasNotChoice = true;
$scope.choiceAllFlag = false;
$scope.saveList[$scope.curPage2].choiceAllFlag = false;
break;
}
}
if(!hasNotChoice){//全选
$scope.applyList.choiceAllFlag = true;
$scope.saveList[$scope.curPage2].choiceAllFlag = true;
}
$scope.saveList[$scope.curPage2].list = $scope.applyList.list;
};
//全选
$scope.choiceAll = function() {
if(!$scope.applyList.choiceAllFlag){
for(var i=0; i<$scope.applyList.list.length; i++){
$scope.applyList.list[i].selected = true;
}
}else{
for(var i=0; i<$scope.applyList.list.length; i++){
$scope.applyList.list[i].selected = false;
}
}
$scope.saveList[$scope.curPage2].list = $scope.applyList.list;
$scope.applyList.choiceAllFlag = !$scope.applyList.choiceAllFlag;
};

对应的HTML代码

          <table class="table table-hover">
<tr class="active">
<th v-click="choiceAll()">
<img v-show="!applyList.choiceAllFlag" src="css/img/all.png" />
<img v-show="applyList.choiceAllFlag" src="css/img/all-active.png" /></th>
<th>序号</th>
<th>协会编号</th>
<th>投资者名称</th>
<th>投资者类型</th>
<th>提交时间</th>
<th>状态</th>
</tr>
<tr v-repeat = "item in applyList.list">
<td v-click="choiceOne(item)">
<img v-show="!item.selected" src="css/img/all.png" />
<img v-show="item.selected" src="css/img/all-active.png" /></td>
<td>{{item.stockCode}}</td>
<td>{{item.investorCode}}</td>
<td>{{item.investorName}}</td>
<td>{{item.rationName}}</td>
<td>{{item.createTime}}</td>
<td>{{item.authStatus}}</td>
</tr>
</table>

技巧:

  try{}catch(){}捕获

  每页初始化次数保持一次。

jq pagination分页 全选、单选的思考的更多相关文章

  1. vue开发购物车,解决全选单选问题

    实现全选单选,在vue中无法通过this获取input中的checkbox的checked属性,但是可以通过vue对input的特殊方式v-model来实现对应数据的绑定,同样也可以通过这种方式实现购 ...

  2. vue分页全选和单选操作

    <!DOCTYPE html> <html> <head> <title>演示Vue</title> <style> ul,li ...

  3. 邮箱性质--全选单选的操作和传值 用属性的name传值

    封装类 using System; using System.Collections.Generic; using System.Web; /// <summary> /// Ha 的摘要 ...

  4. 分别用js和jq实现百度全选反选效果

    js实现过程 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  5. vue-实现全选单选

    在获取列表页面数据时,通过forEach遍历存储数据的对象,给对象中添加一个selected变量,值为布尔值. 点击全选时,通过遍历将对象中selected的布尔值改变 点击单选时,被点中的通过筛选加 ...

  6. checkbox 全选 单选的使用

    绑定数据 if (!IsPostBack) { using (UsersDataContext con = new UsersDataContext()) { Repeater1.DataSource ...

  7. element-ui 里面el-checkbox多选框,实现全选单选

    data里面定义了 data:[],        actionids:[],//选择的那个actionid        num1:0,//没选择的计数        num2:0,//选中的计数  ...

  8. jq checkbox 的全选并ajax传参

    /全选按钮 $("#all").click(function(){ if(this.checked){ $(":checkbox").prop("ch ...

  9. Jquery全选单选功能

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm6.aspx. ...

随机推荐

  1. Tomcat 常用配置及网站部署

    一.同一Tomcat  多个端口部署不同的项目       在tomcat 安装目录下C:/Program Files/apache-tomcat-6.0.29/conf找到server.xml (1 ...

  2. IPC-->PIPO

    Programing python 4th page 228 """ IPC http://www.cnblogs.com/BoyXiao/archive/2011/01 ...

  3. 关于linux下关于ssd的使用

    1. 这几个文件系统可以在挂载的时候使用 discard  选项:ext4, xfs, jfs, vfat 2. 使用 fstrim 命令可以实现周期性的 trim,挂载时使用discard标记可以实 ...

  4. Objective-C基础4

    1.强指针:默认的情况下所有的指针都是强指针,关键字__strong 弱指针:__week关键字修饰的指针 2.ARC:编译器将自动在代码合适的地方插入retain.release.autorelea ...

  5. PowerShell vs. PsExec for Remote Command Execution

    Posted by Jianpeng Mo / January 20, 2014 Monitoring and maintaining large-scale, complex, highly dis ...

  6. linux下使用远程图形界面

    1. 用xrdp的方式(客户端就是windows下的远程桌面程序) http://jingyan.baidu.com/article/d3b74d64bdab5d1f76e60951.html 2. ...

  7. WEB进度条控件

    近段时间为了工作的需要学习了一下写自定义控件,呵呵!以前没写过,近段时间才开始研究的,昨天写了一个WEB状态条控件,可以设置进度条的百分比,也可以设置它的总数与当前的数量来自动计算百分比,可以设置颜色 ...

  8. node平台截取图片模块——jimp

    前几天介绍了一个简单的截图模块——iamges,虽然简单,但是功能还是有很多局限的地方. jimp的优势:1.简单,2.支持回调方式和ES6(promise)语法也可以链式调用 3. 丰富的api   ...

  9. memcache基础知识

    memcached的内存存储机制 Memcached默认情况下采用了名为Slab Allocator的机制分配.管理内存.在该机制出现以前,内存的分配是通过对所有记录简单地进行malloc和free来 ...

  10. OpenGL FAQ

    转自:http://www.cnblogs.com/indif/archive/2011/04/22/2024659.html 1.什么是OpenGL?OpenGL即开放图形库(Open Graphi ...