我试图从JavaScript获取每个列的表头,但是调用tableTest
只返回每行列的数据,有没有办法返回标题,如' name& #39;和'描述'。也许有点tableTest.data-title
<table ng-table="tableTest">
<tbody>
<tr ng-repeat="sample in $data">
<td data-title="'Name'" sortable="'name'">
{{sample.name}}
</td>
<td data-title="'Description'" sortable="'description'">
{{sample.description}}
</td>
</tr>
</tbody>
</table>
由于
答案 0 :(得分:4)
通过javaScript
做到这一点怎么样?
请参阅此Plunker代码
<强> HTML 强>
<table ng-table="tableParams" id="myTable">
<tbody>
<tr ng-repeat="sample in $data">
<td data-title="'Name'" sortable="'name'">
{{sample.title}}
</td>
<td data-title="'Description'" sortable="'description'">
{{sample.description}}
</td>
</tr>
</tbody>
</table>
<script>
//gets table
var oTable = document.getElementById('myTable');
//gets rows of table
var rowLength = oTable.rows.length;
//loops through rows
for (i = 0; i < rowLength; i++) {
//gets cells of current row
var oCells = oTable.rows.item(i).cells;
//gets amount of cells of current row
var cellLength = oCells.length;
//loops through each cell in current row
for (var j = 0; j < cellLength; j++) {
// get your cell info here
var cellTitle = oCells.item(j).getAttribute("data-title");
document.write("Header for Row#" + j + " : " + cellTitle + "<br>");
}
}
</script>
<强>输出强>
Header for Row#0 : 'Name'
Header for Row#1 : 'Description'