jq pagination分页 全选、单选的思考
$().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分页 全选、单选的思考的更多相关文章
- vue开发购物车,解决全选单选问题
实现全选单选,在vue中无法通过this获取input中的checkbox的checked属性,但是可以通过vue对input的特殊方式v-model来实现对应数据的绑定,同样也可以通过这种方式实现购 ...
- vue分页全选和单选操作
<!DOCTYPE html> <html> <head> <title>演示Vue</title> <style> ul,li ...
- 邮箱性质--全选单选的操作和传值 用属性的name传值
封装类 using System; using System.Collections.Generic; using System.Web; /// <summary> /// Ha 的摘要 ...
- 分别用js和jq实现百度全选反选效果
js实现过程 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- vue-实现全选单选
在获取列表页面数据时,通过forEach遍历存储数据的对象,给对象中添加一个selected变量,值为布尔值. 点击全选时,通过遍历将对象中selected的布尔值改变 点击单选时,被点中的通过筛选加 ...
- checkbox 全选 单选的使用
绑定数据 if (!IsPostBack) { using (UsersDataContext con = new UsersDataContext()) { Repeater1.DataSource ...
- element-ui 里面el-checkbox多选框,实现全选单选
data里面定义了 data:[], actionids:[],//选择的那个actionid num1:0,//没选择的计数 num2:0,//选中的计数 ...
- jq checkbox 的全选并ajax传参
/全选按钮 $("#all").click(function(){ if(this.checked){ $(":checkbox").prop("ch ...
- Jquery全选单选功能
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm6.aspx. ...
随机推荐
- 【C#】时间戳转换
今天有时间戳转换的需求,网上找了半天才找到相关代码,经测试有效,特作此笔记和大家分享! 1.时间戳转为C#格式时间 /// <summary> /// 时间戳转为C#格式时间 /// &l ...
- 夺命雷公狗-----React---14--移入移出事件
<!DOCTYPE> <html> <head> <meta charset="utf-8"> <title></ ...
- LAMP环境搭建
安装前说明: 先安装gcc gcc-c++ make 等 可用yum install -y gcc gcc-c++ make 也可以使用rpm安装不过需要注意依赖 1.安装apache 下载链接:ht ...
- java加法流程图
- ADB server didn't ACK
当我们通过eclipse开发Android应用时,会连接真机会使用模拟器进行仿真,有时候启动失败,会提示这样的错误. 工具/原料 Eclipse CMD命令窗口 方法/步骤 首先通过CMD启动adb服 ...
- [转]MySQL innodb buffer pool
最近在对公司的 MySQL 服务器做性能优化, 一直对 innodb 的内存使用方式不是很清楚, 乘这机会做点总结. 在配置 MySQL 的时候, 一般都会需要设置 innodb_buffer_poo ...
- 如何:在 ASP.NET 网页中检测浏览器类型
https://msdn.microsoft.com/zh-cn/library/3yekbd5b(VS.80).aspx private void Button1_Click(object send ...
- 基于layerpage 前后端异步分页
#下载jquery 和 layerpage1.核心分页方法 laypage({ cont: 'page1', //容器.值支持id名.原生dom对象,jquery对象. pages: json.tot ...
- html标签快速转换思想方法
function htmlencode(s){ var div = document.createElement('div'); div.appendChild(document.createText ...
- GoLang语言
1 Go语言基础 1.1 语法详解 1.1.1 注释 /* regexp 包为正则表达式实现了一个简单的库. 该库接受的正则表达式语法为: 正则表达式: 串联 { '|' 串联 } 串联: { 闭包 ...