【发布时间】:2015-09-30 16:42:19
【问题描述】:
我正在尝试通过 JavaScript 将数据动态添加到表中,它返回:
未捕获的类型错误:无法读取未定义的属性“添加”。
编辑:代码在没有row.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>
【问题讨论】:
-
我在你的代码中看不到
t.row声明/初始化 -
您是否调试并查看了 t.row 的值?它是未定义的。
标签: javascript jquery dynamic datatables typeerror