我想显示带有排序过滤器和分页的帖子列表。当我反复将容器编码为#container1
,#container2
时,它就起作用了,依此类推,我想循环所有容器以使用mixitup和使用simplePagination js的分页显示排序过滤器
JQuery,JavaScript
jQuery(document).ready(function(jQuery) {
// First Column Pagination start from here
for(var i=0; i< 3; i++){
function sw_show_pagination(){
jQuery(function(jQuery) {
var pageParts = jQuery(".itemContainer-"+i+" .mix");
var numPages = pageParts.length;
var perPage = 10;
pageParts.slice(perPage).hide();
jQuery(".page-nav-"+i).pagination({
items: numPages,
itemsOnPage: perPage,
prevText:"",
nextText:"",
cssStyle: "compact-theme",
onPageClick: function(pageNum) {
var start = perPage * (pageNum - 1);
var end = start + perPage;
pageParts.hide().slice(start, end).show();
}
});
});
} //end show pagination
sw_show_pagination();
// First Column MixItUp start from here
var containerEl+i = document.querySelector('[data-ref="itemContainer-'+i+'"]');
var config+i = { controls: { scope: 'local' } , callbacks: {
onMixStart: function(state,futureState ){
jQuery(".page-nav-"+i).pagination('destroy');
},
onMixEnd: function(state, futureState){
jQuery(".page-nav-"+i).pagination('redraw');
}
}};
var mixer+i = mixitup(containerEl+i,config+i);
}
});
控制台错误SyntaxError:意外令牌:“ +”
答案 0 :(得分:0)
在变量名中使用'+'是非法的。
更改以下内容:
ContainerEl + i
config + i
mixer + i
jQuery(document).ready(function(jQuery) {
// First Column Pagination start from here
for(var i=0; i< 3; i++){
function sw_show_pagination(){
jQuery(function(jQuery) {
var pageParts = jQuery(".itemContainer-"+i+" .mix");
var numPages = pageParts.length;
var perPage = 10;
pageParts.slice(perPage).hide();
jQuery(".page-nav-"+i).pagination({
items: numPages,
itemsOnPage: perPage,
prevText:"",
nextText:"",
cssStyle: "compact-theme",
onPageClick: function(pageNum) {
var start = perPage * (pageNum - 1);
var end = start + perPage;
pageParts.hide()
.slice(start, end).show();
}
});
});
} //end show pagination
sw_show_pagination();
// First Column MixItUp start from here
var containerEli = document.querySelector('[data-ref="itemContainer-'+i+'"]');
var configi = { controls: { scope: 'local' } , callbacks: {
onMixStart: function(state,futureState ){
jQuery(".page-nav-"+i).pagination('destroy');
},
onMixEnd: function(state, futureState){
jQuery(".page-nav-"+i).pagination('redraw');
}
} };
var mixeri = mixitup(containerEli,configi);
}
});