【问题标题】:Rails Table header row repeatingRails表格标题行重复
【发布时间】:2018-09-18 09:27:26
【问题描述】:

我的表格标题行在循环中的每个玩家之后重复。我尝试在构建列标题后移动循环,但是我只得到一行格式,其余的只是一大堆数据。谢谢。

这就是它的样子:https://imgur.com/5UmURx6

<% @players.each do |player| %>


<table id="myTable" class="tablesorter">
<thead>
<tr>
 <th class="name">Player</th>
 <th class="stat">pV</th>
 <th class="stat">rV</th>

</tr>
</thead>

<tbody>
<tr>

 <td class="name"> <%= player.player %> </td>
 <td class="stat"> <%= player.pv %> </td>
 <td class="stat"> <%= player.rv %> </td>

</tr>

</tbody>
</table>

<% end %>
<% end %>

【问题讨论】:

    标签: ruby-on-rails sorting html-table


    【解决方案1】:

    如果我没听错的话,应该是这样的:

    <table id="myTable" class="tablesorter">
    <thead>
      <tr>
        <th class="name">Player</th>
        <th class="stat">pV</th>
        <th class="stat">rV</th>
      </tr>
    </thead>
    <tbody>
      <% @players.each do |player| %>
        <tr>
         <td class="name"> <%= player.player %> </td>
         <td class="stat"> <%= player.pv %> </td>
         <td class="stat"> <%= player.rv %> </td>
        </tr>
      <% end %>
    </tbody>
    </table>
    

    【讨论】:

    • @frankburke333 欢迎您。附:我想将您的注意力引向代码中额外的 &lt;% end %&gt;
    【解决方案2】:

    尝试将 each 循环放置在 &lt;tr&gt; 标签周围:

    <table id="myTable" class="tablesorter">
      <thead>
        <tr>
           <th class="name">Player</th>
           <th class="stat">pV</th>
           <th class="stat">rV</th>
        </tr>
      </thead>
    
      <tbody>
        <% @players.each do |player| %>
          <tr>
           <td class="name"> <%= player.player %> </td>
           <td class="stat"> <%= player.pv %> </td>
           <td class="stat"> <%= player.rv %> </td>
          </tr>
        <% end %>
    
      </tbody>
    </table>
    

    【讨论】:

    • 做到了。非常感谢丹!
    猜你喜欢
    • 1970-01-01
    • 2018-09-15
    • 1970-01-01
    • 1970-01-01
    • 2021-07-22
    • 1970-01-01
    • 1970-01-01
    • 2012-09-19
    • 2021-01-28
    相关资源
    最近更新 更多