Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript DataTables无法添加行_Javascript_Jquery_Dynamic_Datatables_Typeerror - Fatal编程技术网

Javascript DataTables无法添加行

Javascript DataTables无法添加行,javascript,jquery,dynamic,datatables,typeerror,Javascript,Jquery,Dynamic,Datatables,Typeerror,我试图通过JavaScript动态地将数据添加到表中,它会返回以下内容: 未捕获的TypeError:无法读取未定义的属性“add” 编辑:代码在没有行的情况下工作正常。添加行 相关代码: <html> <head> <link rel="stylesheet" type="text/css" href="./css/jquery.dataTables.min.css"> <script type="text/javascript" src="./li

我试图通过JavaScript动态地将数据添加到表中,它会返回以下内容:

未捕获的TypeError:无法读取未定义的属性“add”

编辑:代码在没有
行的情况下工作正常。添加

相关代码:

<html>
<head>
<link rel="stylesheet" type="text/css" href="./css/jquery.dataTables.min.css">

<script type="text/javascript" src="./lib/jquery.min.js"></script>
<script type="text/javascript" src="./lib/jquery.dataTables.min.js"></script>

<script>
var dataSet = [
    ['1.1','2.1'],
    ['1.2','2.2'],
];

$(document).ready(function() {
    $('#demo').html( '<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>' );
    t = $('#example').dataTable( 
    {
        data: dataSet,
        columns: [
            { "title": "Col 1" },
            { "title": "Col 2" },
        ],
    });

    t.row.add(['1.3', '2.3']) // <-- Fails
});
</script>
</head>

<body>
 <div id="demo" style="width:500px"> </div>
</body>
</html>

变量数据集=[
['1.1','2.1'],
['1.2','2.2'],
];
$(文档).ready(函数(){
$('#demo').html('');
t=$('#示例')。数据表(
{
数据:数据集,
栏目:[
{“标题”:“第1列”},
{“标题”:“第2列”},
],
});

t、 row.add(['1.3','2.3'])/您非常接近。以下是我对您的代码所做的更改:

a、 初始化DataTable时,使用大写字母D。 b、 添加行时使用了.draw()

var数据集=[
['1.1','2.1'],
['1.2','2.2']
];
$(文档).ready(函数(){
$('#demo').html('');
var t=$('#示例').DataTable({
数据:数据集,
栏目:[
{“标题”:“第1列”},
{“标题”:“第2列”}
]
});             
t、 添加(['1.3','2.3']).draw();
});


我看不到
t.row
在您的代码中声明/初始化了t.row的值。您是否调试并查看了t.row的值?它未定义。