1 回答
TA贡献1818条经验 获得超3个赞
修改如下:
1.丢了curr参数。
2.跳页laypage自带参数jump
3.数据会累加是因为重新查询之前没有清空数据。
//查询全部信息
function getInfo(page) {
$.ajax({
type: 'post',
url: '/web/illegalMessages',
//dataType:'json',
data: {
'page': page
},
async: false,
success: function(data) {
//var data = JSON.parse(data);
var list = data.data;
totalRow = data.totalRow; //获取总条数
if (data.flag == 'success') {
$('tbody').html(''); //先清空,否则再次查询会在本页累加数据
for (var i = 0; i < list.length; i++) {
$('tbody').append(
'<tr id="' + list[i].illegalmessageid + '">' +
'<td>' + list[i].deal + '</td>' +
'<td>' + list[i].occurarea + '</td>' +
'<td>' + list[i].platenumber + '</td>' +
'<td>' + list[i].occurtime + '</td>' +
'<td>' + list[i].markImgPath + '</td>' +
'<td>' + list[i].detailImgPath + '</td>' +
'<td>' + list[i].voicePath + list[i].videoPath + '</td>' +
'<td>' + list[i].deal + '</td>' +
'</tr>'
)
}
}
//配置并加载所需模块
layui.config({
base: 'base/lay/modules/'
}).use(['laypage', 'table'], function() {
var laypage = layui.laypage;
var table = layui.table;
//实例化分页
laypage.render({
elem: 'layPage' //分页容器的id
,
layout: ['prev', 'page', 'next', 'limits', 'count'] //排版
,
limit: 10 //每页显示数
,
count: totalRow //总条数
,
curr: page
,
groups: 3 //连续出现的页数
,
theme: '#1E9FFF' //自定义选中色值
,
skip: true //开启跳页
,
jump: function(obj, first) { //点击页码跳页
if (!first) {
$('tbody').html('');
getInfo(obj.curr); //查询,传参:当前页
}
}
});
});
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log(XMLHttpRequest.status);
console.log(XMLHttpRequest.readyState);
console.log(textStatus);
},
})
}
$(function() {
//初始化加载所有信息
getInfo(1);
})
添加回答
举报
