$().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. JDBC代码模板

    import java.sql.Connection; import java.sql.SQLException; import java.util.Properties; import org.ap ...

  2. Android中使用Handler造成内存泄露的分析和解决

    什么是内存泄露?Java使用有向图机制,通过GC自动检查内存中的对象(什么时候检查由虚拟机决定),如果GC发现一个或一组对象为不可到达状态,则将该对象从内存中回收.也就是说,一个对象不被任何引用所指向 ...

  3. c++加法高精度算法

    c++高精度算法,对于新手来说还是一大挑战,只要克服它,你就开启了编程的新篇章,算法. 我发的这个代码并不是很好,占用内存很多而且运行时间很长(不超过1秒),但是很好理解,很适合新手 高精算法的本质就 ...

  4. 将图片插入到excel中

    static void Main(string[] args) { //说明:插入图片 //1.创建EXCEL中的Workbook IWorkbook myworkbook = new HSSFWor ...

  5. String相关的问题

    基本事实:对于字符串常量,如果内容相同,Java认为它们代表同一个String对象.而用关键字new 调用的构造器,总是会创建新的对象,无论内容是否相同.字符串常量是放在常量池(或者叫常量缓冲区)里面 ...

  6. postgresql常用命令

    1.createdb 数据库名称 产生数据库2.dropdb 数据库名称 删除数据库 3.CREATE USER 用户名称 创建用户4.drop User 用户名称 删除用户 5.SELECT use ...

  7. C# : CEF操作

    代码挺差的,仅供学习.参考 class CEFGlueLoader { class CefAppImpl : CefApp { protected override void OnBeforeComm ...

  8. C语言 结构体指针赋值 incompatible types when assigning to type 'char[20]' from type 'char *'

    strcpy(pstudent->name, "guo zhao wei "); 为什么错误,该怎么写,(红色行)     追问 为什么不能直接赋值啊, 追答 用char n ...

  9. Curling 2.0

    Description On Planet MM-21, after their Olympic games this year, curling is getting popular. But th ...

  10. Android下添加新的自定义键值和按键处理流程

            Android下添加新的自定义键值和按键处理流程     说出来不怕大家笑话,我写这篇博客的原因在于前几天去一个小公司面试Android系统工程师,然后在面试的时候对方的技术总监问了我 ...