cureRecordGruop4Doctor={'1':[{'1','lalal'}],'2':[{'1','2'}]} 用javascript生成对应表格
时间: 2024-01-09 09:03:52 浏览: 29
以下是一个简单的 JavaScript 函数,它将 `cureRecordGruop4Doctor` 对象转换为 HTML 表格:
```javascript
function generateTable(cureRecordGruop4Doctor) {
let table = '<table>';
// 添加表头
table += '<tr><th>医生编号</th><th>病历编号</th><th>病历内容</th></tr>';
// 添加表格内容
for (let doctorId in cureRecordGruop4Doctor) {
let cureRecords = cureRecordGruop4Doctor[doctorId];
for (let i = 0; i < cureRecords.length; i++) {
let cureRecord = cureRecords[i];
table += '<tr><td>' + doctorId + '</td><td>' + cureRecord[0] + '</td><td>' + cureRecord[1] + '</td></tr>';
}
}
table += '</table>';
return table;
}
// 示例用法
let cureRecordGruop4Doctor = {
'1': [{'1', 'lalal'}],
'2': [{'1', '2'}]
};
let table = generateTable(cureRecordGruop4Doctor);
document.write(table);
```
这个函数会生成一个带有表头的表格,其中包括医生编号、病历编号和病历内容这三列。每个医生对应一个或多个病历记录,每个病历记录包括编号和内容两个属性。函数会遍历 `cureRecordGruop4Doctor` 对象,将其中的数据逐一添加到表格中。最终,函数会返回一个包含整个表格的 HTML 字符串。