我想要这样的东西:
<table>
<thead>
<tr>
<th>Module</th>
<!-- foreach: months -->
<th data-bind="text: month"></th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<th>Invoices</th>
<!-- foreach: months -->
<td data-bind="text: invoice.amount"></td>
<th data-bind="text: invoicesTotal"></th>
</tr>
<tr>
<th>Taxes</th>
<!-- foreach: months -->
<td data-bind="text: tax.amount"></td>
<th data-bind="text: taxesTotal"></th>
</tr>
</tbody>
</table>
如果所有列都来自数组,我知道如何将列绑定(bind)到数组,但在这种情况下,我更希望第一列和最后一列在月份数组之外定义。
在这种情况下,我未能找到一种方法来迭代月份(如何以及在哪个元素上定义 foreach 绑定(bind))。
注意:即使网格听起来也可以,但它们不适合最终场景。
最佳答案
如果您所拥有的不起作用,则您缺少结束伪标记:
<!-- ko foreach: months -->
<th data-bind="text: month"></th>
<!-- /ko -->
关于javascript - knockout.js 中第一列和最后一列之间具有动态列的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32209726/