简体   繁体   English

数据未填充到JQuery Datatable中

[英]Data not getting populated in JQuery Datatable

I am making an Ajax call and the returned value is stored in "data" variable. 我正在进行Ajax调用,返回的值存储在“数据”变量中。 Now, I want to use this "data" (in the form of JSON object) to bind the table 'templateRegArea'. 现在,我想使用此“数据”(以JSON对象的形式)绑定表'templateRegArea'。

$.ajax({
    url: "Ajax_UserPermissionProfile.aspx/GetTemplatePropertyList",
    method: 'post',
    type: "POST",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    data: "{ 'iAcctId': '" + $('#hidIAcctId').val() + "', 'iTemplateID': '" + templateID + "'}",

    success: function(response) {
        var data = eval((response.d != undefined) ? response.d : response);
        alert(data);
        $('#templateRegArea').DataTable({
            ajax: data,
            columns: [{
                data: data.ID
            }, {
                data: data.Name
            }, {
                data: null,
                className: "center",
                defaultContent: '<a href="" class="editor_edit">Edit</a> / <a href="" class="editor_remove">Delete</a>'
            }]
        });
    },
    error: function(error) {}
}

I am getting the following error. 我收到以下错误。

错误

在此处输入图片说明

有时,数据表希望所有列都与JSON中发送的数据进行映射。

I assume these "ID" and "Name" values are the values you want to put on your table as rows. 我假设这些“ ID”和“ Name”值是要作为行放在表上的值。 The "columns" DataTable property expects to get the names of the columns, not its values. “列” DataTable属性期望获取列的名称,而不是其值。 From the documentation example : 从文档示例中

$('#example').DataTable({
    "columns": [
        { "data": "name" },
        { "data": "position" },
        { "data": "office" },
        { "data": "age" },
        { "data": "start_date" },
        { "data": "salary" }
    ]
});

What you should do is create the columns with "data": "ID" and "data: Name" and then add those values as rows. 您应该做的是使用"data": "ID""data: Name"创建列,然后将这些值添加为行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM