我正在使用带有以下javascript的光滑网格。问题是控件永远不会转到ensureData()。有什么想法吗?
grid.onViewportChanged.subscribe(function (e, args) {
alert('1');
var vp = grid.getViewport();
alert('2');
loader.ensureData(vp.top, vp.bottom);
alert('3');
});
function ensureData(from, to)
{
alert('55');
var maxdata = Math.min(999, data.length);
if (from < 0)
from = 0;
if (to > maxdata)
to = maxdata;
var fromPage = Math.floor(from / PAGESIZE);
var toPage = Math.floor(to / PAGESIZE); // look-ahead
while (fromPage <= toPage) {
if (data[fromPage * PAGESIZE] == undefined) {
data[fromPage * PAGESIZE] = null; // null indicates a 'requested but not available yet'
var order = { "query": searchstr, "offset": (fromPage * PAGESIZE), "count": (((toPage - fromPage) * PAGESIZE) + PAGESIZE), "sort": sortcol, "order": ((sortdir > 0) ? "asc" : "desc") };
req = $.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify(order),
url: "OrderService.svc/GetOrderList",
success: onSuccess,
error: function (jqXHR, textStatus, errorThrown) {
if (textStatus != 'abort')
onError(fromPage, toPage);
}
});
onDataLoading.notify();
}
fromPage++;
}
}
然后显示警报1 然后显示警报2 显示警报(错误加载数据)&amp;最后 警报3显示....
答案 0 :(得分:0)
不应该在页面加载时触发。顾名思义,它会在视口更改时触发,即当用户滚动并且视口中的顶部和底部可见行发生更改时。