我有對象的數組: -如何將對象數組轉換爲表格數據?
[{
"TaAddClaim": {
"claim_id": "CL462573115516",
"date": "2016-11-08"
},
"Employee": {
"full_name": "Admin User"
}
}, {
"TaAddClaim": {
"claim_id": "CL67258688282",
"date": "2016-11-08"
},
"Employee": {
"full_name": "Admin User"
}
}, {
"TaPassAccount": {
"claim_id": "CL462573115516"
},
"0": {
"total_expenses": "4436.00"
}
}, {
"TaPassAccount": {
"claim_id": "CL67258688282"
},
"0": {
"total_expenses": "3236.00"
}
}]
我想在HTML
表中顯示這些數據。我的表結構如下:
$.each(resp, function(indx, obj) {
if (obj.TaAddClaim) {
table += '<tr>';
table += '<td>' + obj.TaAddClaim.claim_id + '</td>';
table += '<td>' + obj.TaAddClaim.date + '</td>';
table += '<td>' + obj.Employee.full_name + '</td>';
}
});
現在的問題是,我無法在表格中顯示的數據total_expenses
。
如果claim_id
的TaAddClaim
與TaPassAccount
的claim_id
匹配,我想要顯示total_expenses
的數據。
在此先感謝。
請嘗試THI: - VAR OBJ = jQuery.parseJSON( '{ 「名」: 「約翰」}'); –
你可以修改json嗎?最明顯的解決方案是返回分組的數據,因爲它應該被分組,而不是作爲不同條目可能相關的對象數組。 – jeroen
您需要在將數組轉換爲json之前對其進行操作 –