2011-10-28 39 views
0

我基於數據庫的一些字段生成表,並且我需要爲每個表指定不同的樣式。如何爲每個表格指定不同的樣式。指定每個表的不同樣式

這是我的代碼

<table width="100%"> 
    <% @content_data['personnel_cv_data_types'].each do |personnel_cv_data_type| %> 
<tr width="100%"> 
<td> 
    <fieldset> 
    <legend> 
    <table style="font-size:13px;"width="100%" class="personnel_cvdata_view_table_first_row"> 
     <tr> 
     <td> 
      <%= @content_data['lable_title_'+personnel_cv_data_type] %> 
     </td> 
     <td> 
      <a onClick="add_new_entry('<%= personnel_cv_data_type %>')">Add&nbsp;<%= @content_data['lable_add_'+personnel_cv_data_type] %></a> 
     </td> 
     </tr> 
    </table> 
    </legend> 

這裏每個表採用相同的風格personnel_cvdata_view_table_first_row,怎麼可能產生具有不同風格類表例如

class="personnel_cvdata_view_table_first_row_1" 
    class=""ersonnel_cvdata_view_table_first_row_2 

等的,我可以爲每個表格分別編寫風格

+0

你想交替/'斑馬'類嗎?或者只是分配給他們的唯一號碼?或記錄的ID?請澄清。 –

+0

對不起沒有其他選擇我需要每個表的不同風格,因爲字段形式數據庫是不同的長度(名稱,教育資格,工作經驗),所以我想組織他們在良好的格式。 – Jens

回答

2

而不是

<% @content_data['personnel_cv_data_types'].each do |personnel_cv_data_type| %> 

使用

<% @content_data['personnel_cv_data_types'].each.with_index do |personnel_cv_data_type, counter| %> 

然後你就可以創建你的表像這樣

<table style="font-size:13px;"width="100%" class="personnel_cvdata_view_table_first_row_<%= counter %>"> 
+0

相同的答案,同一時間=> +1 – apneadiving

+0

Yupp和兩個正確的,給你+1也 – davidb

3

類似這樣的東西似乎符合您的需求:

<% @content_data['personnel_cv_data_types'].each_with_index do |personnel_cv_data_type, index| %> 
... 
<table style="font-size:13px;"width="100%" class="personnel_cvdata_view_table_first_row_<%= index + 1 %>"> 
+0

你們真棒...謝謝。我給了其他人,他沒有太多的聲望。謝謝! – Jens

+0

沒關係,沒問題;) – apneadiving

+0

我喜歡點的傳播。贊成a)擁有一個很酷的名字和b)是一項很好的運動。 –

1

你可以根據一些獨特的標識符添加一個類甚至可能是字符串personnel_cv_data_type本身,如果它是唯一的。

<table style="font-size:13px;"width="100%" class="#{personnel_cv_data_type}"> 
    <tr> 
    <td> 
     <%= @content_data['lable_title_'+personnel_cv_data_type] %> 
    </td> 
    <td> 
     <a onClick="add_new_entry('<%= personnel_cv_data_type %>')">Add&nbsp;<%= @content_data['lable_add_'+personnel_cv_data_type] %></a> 
    </td> 
    </tr> 
</table> 

我不知道具體要進行有關每個風格不同的東西,但是如果名單是確定的,您可以設置樣式上述的每一類型的。

+0

謝謝兄弟!我非常感謝幫助.. – Jens

相關問題