【问题标题】:Table with dynamic columns between first and last column in knockout.js在 knockout.js 中的第一列和最后一列之间具有动态列的表
【发布时间】:2015-08-25 16:50:43
【问题描述】:

我想要这样的东西:

<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>

如果所有列都来自一个数组,我知道如何将列绑定到一个数组,但在这种情况下,我希望第一列和最后一列在月份数组之外定义。

在这种情况下,我没有找到一种方法来迭代几个月(如何以及在哪个元素上定义 foreach 绑定)。

注意:即使网格听起来也不错,但它们不适合最终场景。

【问题讨论】:

    标签: javascript arrays knockout.js data-binding


    【解决方案1】:

    如果你有什么不起作用,你错过了结束的伪标签:

    <!-- ko foreach: months -->
    <th data-bind="text: month"></th>
    <!-- /ko -->
    

    http://knockoutjs.com/documentation/foreach-binding.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-24
      • 1970-01-01
      • 2014-02-09
      • 2014-02-27
      • 2018-01-13
      • 2011-12-14
      相关资源
      最近更新 更多