jquery - 每次按钮单击分页js时如何调用ajax请求
问题描述
我有一个模块,我在其中使用分页 js 插件将我的数据显示为列表
这是我当前的脚本:但是使用此脚本,它会从我的数据库中加载所有数据。
var dataContainer = $('.latest_articles')
$('#pagenation').pagination({
dataSource: function(done) {
$.ajax({
type: 'GET',
url: '/api/dropdownModuleFiles/getall/'+id,
dataType:'JSON',
beforeSend: function() {
dataContainer.html('Loading data ...');
},
success: function(response) {
done(response);
}
});
},
locator: 'items',
totalNumberLocator: function(response) {
// you can return totalNumber by analyzing response content
return Math.floor(Math.random() * (1000 - 100)) + 100;
},
pageSize: 10,
cssStyle: 'light-theme',
callback: function(data, pagination) {
var html = simpleTemplate(data);
dataContainer.html(html);
}
})
function simpleTemplate(data) {
var fileHtml = '<article class="grid_post" id="article_files">';
$.each(data, function(index, item){
var ext = (item.dropdownFileUrl).split('.').pop();
if(ext == 'pdf'){
fileHtml+='<figure>'+
'<figcaption>'+
'<h4 class="grid_post_title">'+item.dropdownFileTitle+'</h4>'+
'<div class="element-block">'+
'<a target="_blank" href="'+item.dropdownFileUrl+'" class="btn link-btn btn-outline btn-rounded">Click here ⇾</a>'+
'</div>'+
'</figcaption>'+
'</figure>';
}
});
fileHtml += '</article>';
return fileHtml;
}
因为它从我的数据库分页加载所有数据看起来像这样。
<< 1 2 3 4 ..... 10 >>
但是当我将查询限制为 10 时,分页只会看起来像这样
<< 1 >>
它会根据我的查询影响分页。我想要实现的是显示前 10 个数据,但分页将根据要加载的数据量显示。然后当我单击下一个/上一个按钮或数字时,它将调用 ajax 请求以加载下一个/上一个 10
解决方案
推荐阅读
- r - How do i compare each row of a timeseries against a constant in R
- java - OpenApi 3.0 注册过滤器以排除具有特定标签的方法
- python - 使用“for”循环结构,生成数字并通过“length”和“%(mod)”结构过滤
- python - Open CV Contour 面积计算错误
- javascript - 如何在 JSX React 中循环遍历对象
- azure - 如何使用 ARM 模板将基础映像添加到开发测试实验室中的公式?
- firebase - 关于在firestore中将数据存储在数组中的问题
- docker - 如何使用 docker 容器创建 kubernetes pod
- javascript - 当我运行 npm run dev 时如何知道编译哪个文件
- tensorflow - 使用机器学习或深度学习在两个节点之间进行链接概率预测,其中给出了节点到节点的映射