0
我有下面的代碼來顯示在數據表中具有屬性和值的對象數組。但是這裏的列標題是硬編碼的,如我在下面的html代碼中所見。我如何根據輸入數據集使其動態化?如何在jQuery數據表中動態顯示列標題
var dataSet = [{
"Latitude": 18.00,
"Longitude": 23.00,
"Name": "Pune"
}, {
"Latitude": 14.00,
"Longitude": 24.00,
"Name": "Mumbai"
}, {
"Latitude": 34.004654,
"Longitude": -4.005465,
"Name": "Delhi"
},{
"Latitude": 23.004564,
"Longitude": 23.007897,
"Name": "Jaipur"
}];
$(document).ready(function() {
$('#example').DataTable({
data: dataSet,
"columns": [
{ "data": "Name" ,"title":"Custom Name"},
{ "data": "Latitude" },
{ "data": "Longitude" },
]
});
});
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Latitude</th>
<th>Longitude</th>
</tr>
</thead>
</table>