如何在jquery中从json格式的对象填充html数据表
从json对象访问数据时遇到问题: json对象来自datatabase:如何在jquery中从json格式的对象填充html数据表,jquery,json,datatables,laravel-8,Jquery,Json,Datatables,Laravel 8,从json对象访问数据时遇到问题: json对象来自datatabase: { "status":200, "remarks":[ { "supplier_id":"2020111", "supplier_name":"John Doe", "contact_number":&qu
{
"status":200,
"remarks":[
{
"supplier_id":"2020111",
"supplier_name":"John Doe",
"contact_number":"sdfsdfsd",
"date_entry":"2020-11-05 10:04:44"
},
{
"supplier_id":"2020112",
"supplier_name":"Jerwen Reloz",
"contact_number":"sd",
"date_entry":"2020-11-05 10:50:03"
},
{
"supplier_id":"2020113",
"supplier_name":"Danny Cane",
"contact_number":"sd",
"date_entry":"2020-11-05 10:50:07"
}
]
}
我只是想用这些数据填充我的html数据表
,我试图阅读datatables
文档,但我找不到正确的解决方案
下面是我处理请求的jquery:
$.ajax({
type: 'GET',
url: '/supplier-list',
dataType: 'json',
encode: true
})
.done(function (data) {
console.log(data) //the format defined above
//i want to populate datatable with this data.
});
和我的html表格:
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>Supplier ID</th>
<th>Name</th>
<th>Contact</th>
<th>Date Entry</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th>Supplier ID</th>
<th>Name</th>
<th>Contact</th>
<th>Date Entry</th>
</tr>
</tfoot>
</table>
供应商ID
名称
接触
日期输入
供应商ID
名称
接触
日期输入
谢谢。对不起,这是修改版。我在JSFIDLE上进行了测试
var json = {
"status":200,
"remarks":[
{
"supplier_id":"2020111",
"supplier_name":"John Doe",
"contact_number":"sdfsdfsd",
"date_entry":"2020-11-05 10:04:44"
},
{
"supplier_id":"2020112",
"supplier_name":"Jerwen Reloz",
"contact_number":"sd",
"date_entry":"2020-11-05 10:50:03"
},
{
"supplier_id":"2020113",
"supplier_name":"Danny Cane",
"contact_number":"sd",
"date_entry":"2020-11-05 10:50:07"
}
]
};
console.log(json);
var row;
for(var i=0; i<json['remarks'].length; i++) {
var array = json['remarks'];
row += " <tr>" +
" <td> " + array[i].supplier_id + "</td>" +
" <td> " + array[i].supplier_name + "</td>" +
" <td> " + array[i].contact_number + "</td>" +
" <td> " + array[i].date_entry + "</td>"+
"</tr>";
}
var table =
" <thead> " +
" <tr> " +
" <th>Supplier ID</th> " +
" <th>Name</th> " +
" <th>Contact</th> " +
" <th>Date Entry</th> " +
" </tr> " +
" </thead> " +
" <tbody> " +
" <tr> " + row + " </tr> " +
" </tbody> " ;
$('#example1').html(table);
var json={
“地位”:200,
“备注”:[
{
“供应商id”:“2020111”,
“供应商名称”:“John Doe”,
“联系人号码”:“sdfsdfsd”,
“日期输入”:“2020-11-05 10:04:44”
},
{
“供应商id”:“2020112”,
“供应商名称”:“Jerwen Reloz”,
“联系人号码”:“sd”,
“日期输入”:“2020-11-05 10:50:03”
},
{
“供应商id”:“2020113”,
“供应商名称”:“Danny Cane”,
“联系人号码”:“sd”,
“日期输入”:“2020-11-05 10:50:07”
}
]
};
log(json);
var行;
对于(var i=0;ii am使用laravel-8