【发布时间】:2023-03-04 03:14:02
【问题描述】:
我有一个集合,需要一张一张地显示为表格。 例如,在集合 0 中,它可以包含 2 条记录的列表,每条记录可以包含 3 列。- 这必须显示在表 1 中
在集合 1 中的下一个它可以包含 3 条记录的列表,每条记录可以包含 3 列 - 这必须显示在表 2 中
这个集合在循环中运行,我必须根据集合 Items 重复它
下面是敲门代码
function TestPageModel() {
var self = this;
self.MHxReport = ko.observableArray([]);
function addMHxReport(columnList ) {
return {
ColumnList: ko.observableArray(columnList)
}
}
function add(term, mhstdat,mhendat) {
return {
Term: ko.observable(term),
Mhstdat: ko.observable(mhstdat),
Mhendat: ko.observable(mhendat)
}
}
var cList = [];
var columnList = [];
var aList = [];
cList.push(new add("cough", "13MAR2018", "10SEP2018"));
cList.push(new add("ashtma", "13MAR2018", "06NOV2018"));
aList.push(new add("blood", "13MAR2018", "10SEP2018"));
aList.push(new add("ear", "13MAR2018", "10SEP2018"));
aList.push(new add("head", "13MAR2018", "10SEP2018"));
columnList[0] = cList;
columnList[1] = aList;
var newobj = new addMHxReport(columnList )
self.MHxReport.push(newobj);
}
$(document).ready(function () {
var testPageModel = new TestPageModel();
ko.applyBindings(TestPageModel);
});
下面是html代码
<div class="row" data-bind="foreach: MHxReport">
<div style="margin:12px 0 12px 0;">
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="table-responsive dsg-btm-shadow" style="border: 1px solid #ccc;margin: 0 0 15px 0px;" >
<table class="dsg-setup dsg-aligntop" border="0" >
<tbody data-bind="foreach: ColumnList" >
<tr>
<td><span data-bind='text: $data'></span></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
问题是我无法将其显示为行和列的表。不确定 缺少什么以及如何让代码在行和列中显示。 任何人都可以帮忙。请提前致谢
【问题讨论】:
标签: knockout.js