Jquery 当i+;1.
我正在使用一个名为pajinate的分页插件,我需要提供一个Show All选项,因此我将ajax调用的索引传递给“item_per_page”。一切都很好,但我需要在索引中添加1,这样我才能得到完整的结果 当我将“每个页面的项目”设置为“i”时,它工作,当我将其设置为“i+1”时,它不工作。对我来说没有意义:Jquery 当i+;1.,jquery,pagination,Jquery,Pagination,我正在使用一个名为pajinate的分页插件,我需要提供一个Show All选项,因此我将ajax调用的索引传递给“item_per_page”。一切都很好,但我需要在索引中添加1,这样我才能得到完整的结果 当我将“每个页面的项目”设置为“i”时,它工作,当我将其设置为“i+1”时,它不工作。对我来说没有意义: $.ajax({ url: "search-by-department-621650415.json", cache: true, dataType : 'jso
$.ajax({
url: "search-by-department-621650415.json",
cache: true,
dataType : 'json',
success : function(results) {
var employeeData = [];
var totalNum;
var startNum = 9;
$.each(results.data, function(i, item){
employeeData.push({
departmentName: item.departnemtName,
firstname: item.firstName,
lastname: item.lastName,
phonework: item.workPhone
});
totalNum = i;
//totalNum = i + 1; breaks when i do this!!
});
$('#employee-name-results').tmpl(employeeData).appendTo('#name-results-container');
Pagination(startNum);
$("a.showall").click(function() {
Pagination(totalNum);
});
}
});
function Pagination(itemsPerPage) {
$('#paging_container-1').pajinate({
items_per_page : itemsPerPage,
num_page_links_to_display : 8,
abort_on_small_lists: true,
nav_label_prev : '<img src="images/icons/icon_prev.png" />',
nav_label_next : '<img src="images/icons/icon_next.png" />'
});
console.log(itemsPerPage);
}
$.ajax({
url:“search-by-department-621650415.json”,
是的,
数据类型:“json”,
成功:功能(结果){
var employeeData=[];
var totalNum;
var startNum=9;
$.each(results.data,function(i,item){
employeeData.push({
部门名称:item.departnemtName,
firstname:item.firstname,
lastname:item.lastname,
电话工作:item.workPhone
});
totalNum=i;
//totalNum=i+1;执行此操作时会中断!!
});
$(“#员工姓名结果”).tmpl(employeeData).appendTo(“#姓名结果容器”);
分页(startNum);
$(“a.showall”)。单击(函数(){
分页(totalNum);
});
}
});
函数分页(itemsPerPage){
$('#paging_container-1')。pajinate({
每个页面的项目:项目页面,
页面链接到显示:8,
小列表上的中止:真,
导航标签上一页:“”,
导航标签下一步:“”
});
console.log(itemsPerPage);
}
试试:
var totalNum = 0;
这将显式地将其设置为数字。尝试强制
i
为数字:totalNum=+i+1代码>
Javascript可能会将其改为字符串。试试这个
$("a.showall").click(function() {
Pagination(results.data.length);
});
在插件中找到if语句:
if(options.abort_on_small_list&&options.items_per_page>=$items.size())返回$page_容器
需要:
if(options.abort_on_small_list&&options.items_per_page>$items.size())返回$page_容器 当只使用“i”时,它将删除分页并显示所有项目,但使用“i+1”时它什么也不做。我得到了正确的数字,只是当我添加+1时,它没有被传递到分页-每页项目中,出于某种奇怪的原因?