现在我有以下html表:
<table id="datatable">
<thead>
<th>fruits</th>
<th>vegs</th>
</thead>
<tbody>
<tr>
<td>apple</td>
<td>potato</td>
</tr>
<tr>
<td>apple</td>
<td>carrot</td>
</tr>
</tbody>
</table>
我想按名称引用列,如下所示:
<script type="text/javascript">
$(document).ready(function() {
/* Init the table */
var oTable = $('#datatable').dataTable( );
//get by sTitle
console.log(oTable);
var row = oTable.fnGetData(1)
console.log(row['vegs']);//should return 'carrot'
} );
</script>
当数据源是 DOM 时,是否有一个 javascript 函数fnGetData()
来返回对象而不是数组?