当前我有一个场景,我必须加载滚动条scrollevent上的记录。 我有一个空的下拉列表,在第一次加载时,我附加了从服务器检索到的前20条记录。 在下拉滚动我从服务器获取下20条记录并追加到下拉菜单中。 我正在滚动条事件上重复此过程,并将下一个20和下20个记录添加到下拉列表中。Jquery加载所有记录
以下是我的代码/算法。
我的问题是:我们有任何选项一次加载所有记录,而不是从服务器加载20?
缺点:我的odata一次只返回20条记录。它的页面大小设置为20.我无法控制odata更新。我必须循环场景,每次获得20到20,并且在页面加载时它应该总结在一起。
var nextCitiesLink = null;
var pgLoading = false;
$("#SelectedNames").bind('scroll', function(e) {
loadCityNames();
});
function loadCityNames() {
if (!pgLoading && nextLinkPgs != null) {
pgLoading = true;
$.ajax({
type: "GET",
url: nextCitiesLink,
crossDomain: true,
cache: false,
contentType: 'application/json; charset=utf-8',
xhrFields: {
withCredentials: true
},
success: function (result) {
debugger;
var namesDrpdown = $('#SelectedNames');
$.each(result.value, function(val, data) {
namesDrpdown.append($('<option></option>').val(data.Id).html(data.Name));
});
nextCitiesLink= "odatalink&$skip=20";
pgLoading = false;
},
complete: function() {
}
});
}
}