html - AngularJS - 来自动态生成的 JSON 的表,具有各种键名
问题描述
我正在尝试从动态生成的 JSON 创建一个表。例如 JSON 可能如下所示:
[{"date": "10-10-2010", "Cost":"10", "Column3": 20} ...]
但它也可以是这样的:
[{"date": "10-10-2010", "Column1":"ex", "Column2": 1, "Column4": "text"} ...]
我希望列的标题是 JSON 键的名称,而行单元格是这些键的值。有什么简单的方法可以实现这一目标吗?
解决方案
For header you need to get first row of json data like this:
<thead>
<tr>
<th ng-repeat="(header, value) in jsonData[0]">
{{header}}
</th>
</tr>
</thead>
Afterward you should iterate tbody like this:
<tbody>
<tr ng-repeat="rowData in jsonData">
<td ng-repeat="cellData in rowData">
{{cellData}}
</td>
</tr>
</tbody>
This is easiest way to bind dynamic html table.
Hope this will work for you!!
推荐阅读
- geolocation - 有没有办法绕过量角器测试中的 Chrome 地理定位对话框?
- c# - 如何从不同的用户控件访问 listView?
- powershell - 如何使用 Powershell 在本地更改 Sharepoint 2019 中多个视图的样式
- rust-tokio - 使用带有侦听器连接的 FramedRead 似乎总是没有准备好
- java - 尝试流式传输到自定义 RTMP 时,DJI Mobile SDK 中出现 LiveStreamManager 错误 -3?
- c# - 重定向登录按钮
- node.js - 我无法启动我的反应服务器..我不知道该怎么办!还删除了缓存并再次安装了节点模块
- python - 将集合转换为可散列类型
- c# - EF Core Exception Microsoft.EntityFrameworkCore.DbUpdateException 不确定为什么会抛出这个异常
- http - 在 Fiddler 中,确定下载资源(如图像、js、css)所花费的时间