Я столкнулся с проблемой в javascript. Я хочу загрузить json data
в файл Excel. Как загрузить json data
из reports
для каждой строки?
Что мне делать? кто-нибудь мне поможет?
var responseList = [{ //this is a sample data
"summary": {
"id": 3,
"user_id": "10",
"file_name": "demo.xlsx",
"template_name": "test",
"success": "0",
"fail": "0",
"created_at": "2020-07-10 14:02:13",
"updated_at": "2020-07-10 14:02:13"
},
"reports": [ //download this data into excel file
{
"id": 5,
"user_id": "10",
"name": "Alex",
"number": "3433095622",
"file_name": "demo.xlsx",
"template_name": "test",
"status": "fail",
"sumarry_repo_id": "3",
"created_at": "2020-07-10 14:02:13",
"updated_at": "2020-07-10 14:02:13"
},
{
"id": 6,
"user_id": "10",
"name": "John",
"number": "3005095634",
"file_name": "demo.xlsx",
"template_name": "test",
"status": "fail",
"sumarry_repo_id": "3",
"created_at": "2020-07-10 14:02:13",
"updated_at": "2020-07-10 14:02:13"
}
]
}];
var table = document.querySelector('#my-table');
var tbody = document.createElement('tbody');
table.appendChild(tbody);
for (var i = 0; i < responseList.length; i++) {
var tr = tbody.insertRow();
var summary = responseList[i]["summary"];
var report = responseList[i]["reports"];
console.log(summary);
for (var key in summary) {
if (summary.hasOwnProperty(key)) {
console.log(key + " -> " + summary[key]);
var td = tr.insertCell();
td.innerHTML = summary[key];
}
}
var td = tr.insertCell(-1);
// td.innerHTML = responseList[i]["reports"];
td.innerHTML = `<a onclick="tableToExcel('my-table', 'W3C Example Table');">Download</a>`;
}
var tableToExcel = (function() {
//Download JSON data reports array into excel file
})()
<table id="my-table" border="0">
<thead>
<tr>
<th>ID</th>
<th>User ID</th>
<th>File name</th>
<th>Template name</th>
<th>Success</th>
<th>Fail</th>
<th>Created at</th>
<th>Updated at</th>
</tr>
</thead>
</table>
проверьте получить URL-адрес API
ПОЛУЧИТЬ URL-адрес = https://globemed.codupcloud.com/public/user/10/summary