javascript 数据表未捕获的类型错误:无法设置未定义的属性“0”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23154317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 00:26:43  来源:igfitidea点击:

DataTables Uncaught TypeError: Cannot set property '0' of undefined

javascriptjqueryasp.net.netdatatables

提问by noobprogrammer

I have a repeater and wrap it all with DataTableslibrary. Here is the following js function.

我有一个中继器,并用DataTables库将其全部包装起来。这是以下js函数。

function createDataTable() {
    $(document).ready(function() {
        $('#tblMessages').dataTable({
            "sPaginationType": "full_numbers",
            "sDom": '<"clreol"lf><"scrollable_datatable"rt><"clreol"ip>',
            "bPaginate": true,
            "bLengthChange": false,
            "bFilter": true,
            "bInfo": false,
            "bAutoWidth": false,
            "bAutoHeight": false,
            "bSort": false,
            "bStateSave": true,
            "iCookieDuration": 60*60*24
        });
    });
}

I got no pagination at all just scroll bar on the right side of the repeater. And I got this on console:

我根本没有分页,只有中继器右侧的滚动条。我在控制台上得到了这个:

Uncaught TypeError: Cannot set property '0' of undefined jquery.dataTables.min.js:366
Y                                                        jquery.dataTables.min.js:366
(anonymous function)                                     jquery.dataTables.min.js:454
jQuery.extend.each                                       jquery.min.js:21
jQuery.fn.jQuery.each                                    jquery.min.js:12
i.fn.dataTable                                           jquery.dataTables.min.js:434
(anonymous function)                                     Message.aspx:156
jQuery.fn.extend.ready                                   jquery.min.js:26
createDataTable                                          Message.aspx:152

What's wrong? And what should I do?

怎么了?我该怎么办?

回答by Gyrocode.com

Check your table structure:

检查您的表结构:

  • Number of columns (th) in theadsection must equal number of columns (td) in tbodysection. See manualfor proper HTML structure.

  • If you're using colspanor rowspanattributes for thelements in theadsection, make sure that each column has one unique thelement. See this examplefor more info and demonstration.

  • 部分中的列数 ( th)thead必须等于部分中的列数 ( td) tbody。有关正确的 HTML 结构,请参阅手册

  • 如果您在部分中为元素使用colspanrowspan属性,请确保每一列都有一个唯一的元素。有关更多信息和演示,请参阅此示例ththeadth