JSONの配列2次元の値でテーブルを作成したい。これは私が作ったコードです:
データ
var data = {"ver[
{"0":"1","id_pemasang":"1","1":"1","id_jenis_pemasang":"1","2":null,"npwp":null,"3":"Yos Sudarso","nama":"Yos Sudarso","4":"Perumahan Griya Perwita No.10","alamat":"Perumahan Griya Perwita No.10","5":"Yogyakarta","kota":"Yogyakarta","6":"0274-541056","telepon":"0274-541056","7":"08134570378","handphone":"08134570378","8":"0","diskon":"0"},
{"0":"2","id_pemasang":"2","1":"2","id_jenis_pemasang":"2","2":"34.081.203.1-342.000","npwp":"34.081.203.1-342.000","3":"CV. Prima Agung","nama":"CV. Prima Agung","4":"Jl. Cenderawasih No.72 Warungboto","alamat":"Jl. Cenderawasih No.72 Warungboto","5":"Yogyakarta","kota":"Yogyakarta","6":"0274-878906","telepon":"0274-878906","7":null,"handphone":null,"8":"5","diskon":"5"},
{"0":"3","id_pemasang":"3","1":"2","id_jenis_pemasang":"2","2":null,"npwp":null,"3":"PT. Tampil Jaya","nama":"PT. Tampil Jaya","4":"Jl. Alamanda No.3","alamat":"Jl. Alamanda No.3","5":"Yogyakarta","kota":"Yogyakarta","6":"0274-552233","telepon":"0274-552233","7":null,"handphone":null,"8":"20","diskon":"20"}
]};
html
<table class="table table-striped table-bordered table-data-omset">
<tbody></tbody>
</table>
jQuery
var tableOmset = $('table.table-data-omset');
var tbodyTableOmset = tableOmset.find('tbody');
var rowTbodyTableOmset = '<tr></tr>';
for(var a=0; a<data.ver.length; a++){
tbodyTableOmset.append(rowTbodyTableOmset);
for(var b=0; b<5; b++){
if(data.ver[a][b] == null){
data.ver[a][b]= '';
}
tbodyTableOmset.find('tr').append('<td>'+data.ver[a][b]+'</td>');
}
}
しかし、実行または実行した後、結果は成功しましたが、良くないようです。これは結果画像です:
この問題から私を助けてくれることを願っています。