$().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. git commit 代码时提示: Warning: Your console font probably doesn‘t support Unicode.

    git 提交代码是会遇到以下问题, git commit 代码时提示: Warning: Your console font probably doesn‘t support Unicode. If ...

  2. Db2数据库的备份和恢复

    DB2数据库备份与恢复 1.    备份 1.1离线备份(必须在数据库所在PC机进行操作) STEP 1 连接到要备份的数据库 C:\Documents and Settings\Administra ...

  3. java 支付宝 第三方即时到账支付 接口

    alipay 的几个内核功能文件:=================================================================================== ...

  4. tomcat 默认目录修改

    引用:http://andrewyu.blog.51cto.com/1604432/544659 Tomcat7跟以前的版本一样,默认的发布程序是/usr/local/tomcat/webapps/R ...

  5. C#开发Windows服务 入门

    Microsoft Windows 服务(即,以前的 NT 服务)使您能够创建在它们自己的 Windows 会话中可长时间运行的可执行应用程序. 服务可以在计算机启动时自动启动,可以暂停和重新启动而且 ...

  6. html标签中meta属性使用介绍

    前言 meta是html语言head区的一个辅助性标签.也许你认为这些代码可有可无.其实如果你能够用好meta标签,会给你带来意想不到的效果,meta标签的作用有:搜索引擎优化(SEO),定义页面使用 ...

  7. Thinkphp批量添加数据

    //新建规格public function construction(){ $id = $_GET['id'];//dump($id);die; $this->assign('id', $id) ...

  8. Dynamics AX 2012 R2 业务系列-采购业务流程

    在博文Dynamics AX R2 业务系列中,Reinhard对这个系列做了一个规划,下面我们就按照规划开始说业务吧. 国际惯例,从采购开始. 1.采购的主要职责 简单点说,采购的主要职责,是从供应 ...

  9. DNS-3

  10. [转]CocoaPods安装和使用教程

    转载地址:http://code4app.com/article/cocoapods-install-usage 目录 CocoaPods是什么? 如何下载和安装CocoaPods? 如何使用Coco ...