angular - JSON到Angular中的动态HTML表
问题描述
如何创建具有列和行的动态 Html 表?下面是 JSON 数据,我想使用这些数据创建 HTML 表:
{
"columnNames": [
"Applicant ID(id|Optional)",
"Roll No",
"Applicant Name",
"Password",
"CA ID",
"Shift Name",
"Shift Date",
"Start Time",
"End Time"
],
"rows": [
[
"122",
"18",
"Amit",
"12345",
"42",
"testShift2",
"2019-12-31",
"13:00",
"16:00"
]
]
}
解决方案
假设您的 json 存储在data
,
试试这样:
<table>
<tr>
<th *ngFor="let item of data.columnNames">{{item}}</th>
</tr>
<tr *ngFor="let rowData of data.rows">
<td *ngFor="let el of rowData">{{el}}</td>
</tr>
</table>
推荐阅读
- ios - 在 Xcode 11 中分组时无法创建类的实例
- r - Suppress line breaks created by RMarkdown
- c# - 如何获取数据列表并像 C# 中的模型一样返回?
- reactjs - 在没有动作调度的情况下测试连接的功能组件
- angular - 有没有办法在 P5.js 中创建模型之间的机械关系?
- javascript - 有什么方法可以选择``标签吗?使用 `getElementById("bodyTagId")` 但不使用 `getElementsByTagName("body")`
- axios - 如何在 Phoenix 上使用 axios JSON 发布
- python - 何时接受使用检测虚假配置文件的评级偏离平均协议?
- r - R - 如何在 25 x 4 网格而不是 10 x 10 网格中绘制 10 个变量的成对比较?
- google-app-engine - 如何对 Google Cloud App Engine 任务处理程序进行身份验证