html - 如何将动态列表从 AngularJS 绑定到 Html 表?
问题描述
我有一个角函数
vm.OpenBManageContractBillingReport = function () {
reportService.GetContractBillingList(vm.Search).then(function (response) {
console.log(response);
vm.contractBillingReportList = response;
}, function (err) {
});
};
它给出了 API 列表的输出,动态列表存储在 vm.contractBillingReportList 中。但输出可能会有所不同根据开始日期和结束日期参数在vm.search
. 例如:- IF start Date Parameter is 1/1/2018
and End Date Parameter is31/1/2018
结果仅提供一列 January 2018。类似地,IF start Date Parameter is 1/1/2018
and End Date Parameter is31/12/2019
结果提供 24 Col 从 2018 年 1 月到 2019 年 12 月。我该怎么做将此数据与 HTML 表中的标题列绑定?
<div class="clearfix">
<div class="reportTable">
<div class="col-sm-12" style="padding:0;">
<table class="table table-bordered">
<thead>
<tr></tr>
</thead>
<tbody>
<tr ng-repeat="item in vm.contractBillingReportListtrack by $index">
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
解决方案
假设 contractBillingReportList 是一个对象数组,其中包含所需对象的键作为标题。只需循环第一个元素中的键并将这些键显示为标题。
<tr>
<th ng-repeat="(header, value) in vm.contractBillingReportList[0]">{{header}}</th>
</tr>
推荐阅读
- typescript - ngModel1 无法获取
- reactjs - Tailwind 自动完成功能不适用于 Intellij Idea Ultimate - ReactJs
- asp.net-core - IApplicationBuilder 扩展 UseEndpoints 在哪个 nuget 包中?
- selenium - 为什么 Selenium 启动 Chrome 不显示保存密码对话框?
- docker - Docker 卷内容未复制到容器
- javascript - 如何在 HTML 中向我的栏添加值指示滑块
- python - 用列值减去数据帧行
- exception - 关于从文本文件和异常中生成数据的问题
- types - 阿格达。冒号前后的参数
- graph - Networkx中的多层图和使用节点属性