1
我有以下SQLite表在我的末日應用程序:西納特拉紅寶石遍歷SQLite的數據轉換成一個HTML列
+----------------------------------+
| location area |
+----------------------------------+
| Maine 1 |
| Syracuse 2 |
| Northport 3 |
| NYC 4 |
| Coatesville 4 |
| Erie 4 |
| Dayton 5 |
| Chicago 6 |
| Dallas 6 |
+----------------------------------+
我想從這個數據看起來像下面創建一個HTML表:
<table>
<thead>
<tr>
<th>Area 1</th>
<th>Area 2</th>
<th>Area 3</th>
<th>Area 4</th>
<th>Area 5</th>
<th>Area 6</th>
</tr>
</thead>
<tbody>
<tr>
<td>Maine</td>
<td>Syracuse</td>
<td>NorthPort</td>
<td>NYC</td>
<td>Dayton</td>
<td>Chicago</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td>Coatesville</td>
<td></td>
<td>Dallas</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td>Erie</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
我可以很容易地通過每個區域迭代,幷包含有兩個嵌套循環內的位置,但由於表的方式TD和TR工作,我不知道如何遍歷每個區域的位置成一列
我想我已經得到了表低着頭:
<thead>
<tr>
<% @table_areas.each do |x| %>
<th><%= x.area %></th>
<% end %>
</tr>
</thead>
,但我似乎無法找出休息。每個區域內的區域和位置會經常變化,所以我需要動態創建它。
尼斯存儲在數據庫中的字符串,我結束了使用引導的[網格系統] (http://getbootstrap.com/css/#grid)將列定位爲並排div,但您的解決方案看起來也不錯。有很多方法可以完成工作 – pca2