0

我正在使用带有以下 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....

4

1 回答 1

0

它不应该在页面加载时触发。顾名思义,它会在视口发生变化时触发,即当用户滚动并且视口中的顶部和底部可见行发生变化时。

于 2013-04-23T17:24:48.003 回答