我正在使用带有以下 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,然后显示警报(错误加载数据),最后显示警报 3....