I want to display data in table row while extracting values from map object using JavaScript while AJAX success.
Below is my response that I got from server side:
reportData:
Compute: [2233.36, 2097.09, 2241.42, 2135.11, 2489.97, 2548.01, 2500.82, 2502.82, 2618.89, 2861.08, 2809.17]
Disks: [985.73, 966.29, 987.02, 959.48, 1012.96, 1010.27, 1018.69, 1013.26, 1015.25, 1075.85, 1090.98]
Images: [0.56, 0.56, 0.57, 0.55, 0.57, 0.56, 0.57, 0.57, 0.57, 0.6, 0.6, 0.59, 0.29, 7.16]
Snapshots: [15.75, 11.09, 1.7, 1.65, 7.84, 7.68, 0.26, 1.45, 9.9, 4.55, 7.36, 7.15, 3.5, 79.87]
Total: [2233.36, 2097.09, 2241.42, 2135.11, 2489.97, 2548.01, 2500.82, 2502.82, 2618.89, 2861.08, 2809.17]
Virtual Machine: [1231.32, 1119.14, 1252.13, 1173.43, 1468.61, 1529.5, 1481.3, 1487.53, 1593.17, 1780.08, 1710.24]
So, this reportData is basically a Map object having compute, disks etc as values and these values further contains an array of some data. So I want to display like this:
compute 2233.36 2097.09 2241.42 .....
disks 985.73 966.29 987.02 .....
images 0.56 0.56 0.57 .....
.... and so on
This is my below code, and through this I am not able to render my table body as I am expecting.
function getReportData(report_id, client_id){
$.ajax({
url: "/emerge/mvc/ajax/clientreportsearch/ReportCostData",
data: {
report_id: report_id,
client_id: client_id
},
type: "POST",
success: function (response) {
var tbody = "", data = "", td1 = "", td2 = "";
var mapEntry = "";
if(response.reportData != null){
mapEntry = response.reportData;
Object.keys(mapEntry).forEach(function(value, key){
if(value != 'Total'){
td1 = td1+ "<td>"+key+"</td>";
data = data + "<tr>"+td1;
for(var i = 0; i < value.length; i++){
td2 = td2 + "<td>"+value[i]+"</td>";
}
}
});
tbody = tbody+data;
document.getElementById('thead').innerHTML = thead;
document.getElementById('reportdataDiv').style.display = "inline";
}
},
error: function (error) {
console.log(`Error ${error}`);
}
});
}
So, is there better solution?
Thank you.

