我已经使用https://datatables.net/reference/api/rows.add%28%29链接工作,但数据显示为[object,object]
. 如何将对象显示为字符串。我用过JSON.stringify(obj)
它也不起作用。
HTML
<table id="exampleTable">
<thead>
<tr>
<th>Year</th>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tbody>
<tr>
<td>2012</td>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>2012</td>
<td>February</td>
<td>$80</td>
</tr>
</table>
JS
$('#addRows').click();
var table3 = $('#exampleTable').DataTable();
$('#addRows').on( 'click', function () {
table3.row.add(
[ { "Year": "Tiger Nixon", "Month": "System Architect", "Savings": "$3,120" },
{"Year": "Tiger Nixon", "Month": "System Architect", "Savings": "$3,120" }]
).draw();
});