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>