HTML部分代码
JS代码
//分页
var droploader = null;
var pageNum = 1;
var tabTarget = "pkConList1"; //默认tab标签 切换tab 改变 tabTarget
$(function () {
getEvaluationList();//初始载入,(搜索、分类功能时调用此方法)
});
function getEvaluationList(me) {
if (me == null) {
$(window).unbind("scroll");//解绑每次点击请求调用此方法时的scroll事件
pageNum = 1;
$("#list-box").html("");//清空tab1的数据重新获取高度,否则切换tab会保留在之前位置,造成多次请求
$("#record-list-box").html("");
}
if(tabTarget == "pkConList1"){//根据tab标签异步请求后台分页接口
var url = '/course/evaluation/list';
$.ajax({
type: "POST",
data: {
courseCategoryId: chooseCategoryId, //分类参数(根据需要去除或保留)
key: $("#searchInput").val(),//搜索参数(根据需要去除或保留)
pageSize: 6,
page: pageNum
},
url: url,
success: function (data) {
var list = data.data;
var interHtml = getInterHtml(list);
if (me == null) {
$("#list-box").html(interHtml); //第一次请求载入数据
$("ul.curseConList li:nth-child(2n)").css("margin-right", "0");//本处用于调整样式(如果有样式修改,一定要先处理样式,否则获取的高度是之前的高度)
initScroll(true);
} else {
if (list.length > 0) {
$("#list-box").append(interHtml); //第二次请求追加数据
} else {//如果没有数据
me.noData();//用于显示“到底了”
me.lock();//锁定滑动(可不要)
}
$("ul.curseConList li:nth-child(2n)").css("margin-right", "0");
initScroll(false);
}
}
});
}
if(tabTarget == "pkConList3"){
var url = '/course/evaluation/recordList';
$.ajax({
type: "POST",
data: {
status: evaluationStatus,
pageSize: 6,
page: pageNum
},
url: url,
success: function (data) {
var list = data.data;
var interHtml = getInterHtml(list);
if (me == null) {
$("#record-list-box").html(interHtml);
$("ul.curseConList li:nth-child(2n)").css("margin-right", "0");
initScroll(true);
} else {
if (list.length > 0) {
$("#record-list-box").append(interHtml);
$("ul.curseConList li:nth-child(2n)").css("margin-right", "0");
} else {
me.noData();
me.lock();
}
initScroll(false);
}
}
});
}
}
// 初始化dropload
function initScroll(first) {
if (first) {//是否第一次
droploader = null;
$(".dropload-down").remove();//去掉底部多个“到底了字样”
droploader = $('.droploader').dropload({
scrollArea: window,
// 2 . 上拉加载更多 回调函数
loadDownFn: function (me) {
pageNum++;
getEvaluationList(me);
}
});
droploader.unlock();//解锁之前到底后的锁定 否则上拉加载不触发。droploader.resetload();
} else {
droploader.resetload();
}
}