简体   繁体   English

无法读取 undefined(...) 的属性“_aData” - 数据表

[英]Cannot read property '_aData' of undefined(…) - Datatables

I'm trying to read data() from a cell in a datatable which has a button inside it, but I'm getting en error.我想读取data()从一个细胞datatable这里面有一个按钮,但我得到的连接错误。

This is my Datatable definition:这是我的Datatable定义:

$("#example").DataTable({
                destroy: true,
                "columnDefs": [{
                    orderable: false,
                    targets: 0
                }],
                "columns": [
                    {
                        "data": "slno",
                        "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                            $(nTd).html('<a href="AddNewTicket.aspx?subjectID=' + oData.subjectID + '&subject_id=' + oData.subject_id + '&serviceID=' + oData.crm_services_id + '&severityID=' + oData.severityID + '&statusID=' + oData.statusID + '&callerID=' + '66355356' + '">' + oData.slno + '</a>');
                        },
                    },
                    { "data": "status_message" },
                    { "data": "crm_services_id" },
                    { "data": "subject_id" },
                    { "data": "severity_id" },
                    {"data": "user_id" },
                    { "data": "status_id" },
                    {
                        "data": "caller_number",
                        "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                            $(nTd).html('<button class="btn btn-primary" id= "' + oData.subjectID + '">Call Customer</button>');
                        },
                    }
                ],
                select: {
                    style: 'os',
                    selector: 'td:first-child'
                },
                "data": response,
                "sDom": '<"top">tip'
            });

And here is where I'm trying to fetch the data:这是我试图获取数据的地方:

var table = $("#example").DataTable();
        $('#example tbody').on('click', 'button', function () {
            var subjectID = $(this).attr('id');
            var thisData = table.row($(this).parents('tr')).data();
            var userID = thisData[7];
            sendCallRequest(subjectID, userID);
        });

Here is the error I'm getting:这是我得到的错误:

Cannot read property '_aData' of undefined(…)无法读取 undefined(...) 的属性“_aData”

Any suggestions please?请问有什么建议吗?

Try unbinding the event for your buttons before you re-assign them:在重新分配按钮之前,尝试解除它们的事件绑定:

var table = $("#example").DataTable();

    $('#example tbody').off('click');

    $('#example tbody').on('click', 'button', function () {
        var subjectID = $(this).attr('id');
        var thisData = table.row($(this).parents('tr')).data();
        var userID = thisData[7];
        sendCallRequest(subjectID, userID);
    });

Why am I suggesting this: I have a pretty similar problem, where DataTables is not able to call the rowReorder event.我为什么要这样建议:​​我有一个非常相似的问题,其中 DataTables 无法调用 rowReorder 事件。 I also create my table via AJAX / dynamically (which you seem to do aswell), so obviously my event listener (in my case for table.on('row-reorder')) was bound multiple times.我还通过 AJAX / 动态创建我的表(您似乎也这样做),所以显然我的事件侦听器(在我的情况下为 table.on('row-reorder'))被多次绑定。 After first removing the event listener and readding it, finally I got this to work.在首先删除事件侦听器并阅读它之后,我终于开始工作了。

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

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