【问题标题】:Jekyll and Liquid - Filling table rows with arrayJekyll 和 Liquid - 用数组填充表格行
【发布时间】:2014-12-10 21:26:13
【问题描述】:

我在用数组填充表格行时遇到了一些问题。

我想要达到的目标:

标题行和第一列工作正常,但我没有得到正确的数字,第一行仅包含数组的第一个数字(即 50),第二行仅包含数组中的第二个数字等等

我的代码:

---
exercises: [Burpees, Squats, Pull ups, Push ups]
rounds: 5
reps: [50, 40, 30, 20, 10]
---

<table class="responsive-table">
    <thead>
      <tr>
        <th scope="col">Round</th>
        {% if page.exercises %}
            {% for exercise in page.exercises %}
            <th scope="col">{{ exercise }}</th>
            {% endfor %}
        {% endif %}
      </tr>
    </thead>

    <tbody>
     {% for n in (1..{{page.rounds}}) %}  
     <tr>
        <th scope="row">Round {{ n }}</th>

        <!--  THIS PART DOESNT WORK
        {% for exercise in page.exercises %}   
            <td data-title="{{ exercise }}"> {{ page.reps }} </td>   
        {% endfor %}
        -->

     </tr>     
     {% endfor %}
    </tbody>
</table>

如何按照图片中的方式填充单元格?

【问题讨论】:

    标签: arrays html-table jekyll tablerow


    【解决方案1】:
    exercises: [Burpees, Squats, Pull ups, Push ups]
    reps: [50, 40, 30, 20, 10]
    ---
    <table class="responsive-table table">
      <thead>
        <tr>
          <th scope="col">Round</th>
          {% for exercise in page.exercises %}
          <th scope="col">{{ exercise }}</th>
          {% endfor %}
        </tr>
      </thead>
      <tbody>
        {% assign total = 0 %}
        {% for rep in page.reps %}
        {% assign total = total | plus: rep %}
        <tr>
          <th scope="row">Round {{ forloop.index }}</th>
          {% for exercise in page.exercises %}
          <td data-title="{{ exercise }}"> {{ rep }} </td>
          {% endfor %}
        </tr>
        {% endfor %}
      </tbody>
      <tfoot>
        <tr>
          <th scope="row">Sum</th>
          {% for exercise in page.exercises %}
            <td>{{ total }}</td>
          {% endfor %}
        </tr>
      </tfoot>
    </table>
    

    【讨论】:

    • 是否有可能总结所有代表?
    猜你喜欢
    • 2016-03-11
    • 2020-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-09
    相关资源
    最近更新 更多