0

我有以下函数应该更新我的 ASP.NET 站点母版页中的数据表:

    function refreshTable(oTable) {
        var table = $(oTable).dataTable();
        var oSettings = table.fnSettings();

        //Retrieve the new data with $.getJSON. You could use it ajax too
        $.getJSON(oSettings.sAjaxSource, null, function (json) {
            table.fnClearTable(this);

            for (var i = 0; i < json.aaData.length; i++) {
                table.oApi._fnAddData(oSettings, json.aaData[i]);
            }

            oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
            table.fnDraw();
        });
    }

如果将附件添加到站点,则调用此函数以刷新表 - 这是它应该刷新的数据表设置。

var DeleteClicked = false;
var oTable;

$(document).ready(function () {
 oTable = $('#infoTable').dataTable({
        "aaSorting": [[6, "desc"]],
        "bProcessing": true,
        "sAjaxSource": '/Web/Handlers/infoTableHandler.ashx',
        "aoColumns": [
            { "mData": "ID", "bVisible": false },
            { "mData": "Type" },
            { "mData": "Received" },
            {
                "mData": "Action", "sWidth": "100px", "mRender": function (data, type, row) {
                    var id = row.ID;
                    return "<input type=button id=" + id + " onclick='DeleteFile(" + id + ")' class=buttonBlue value=Delete />";
                },
            },
            { "mData": "IsImage", "bVisible": false }
        ],
        "bDeferRender": true,
    });

但是 - 如果我在 Chrome 中打开开发人员工具,我会收到一条错误消息,提示 sAjaxSource 为空,因此我无法从中获取值 - 所以 oSettings 为空,然后我无法访问 sAjaxSource - 有人看到这里有什么问题吗?

4

1 回答 1

1

您基本上是在refreshTable. 请尝试:

function refreshTable() {
        var oSettings = oTable.fnSettings();
        ...
}

并直接引用全局oTable而不是局部table变量

于 2013-07-10T11:23:58.923 回答