2015-10-20 84 views
0

在我的rails項目中,我得到了一個下拉列表,在這個下拉列表中我想選擇特定的用戶並查看錶格中的項目。Dropdown select table

下拉:

<ul class="dropdown-menu dropdown-user users"> 
    <% @list.each do |i| %> 
    <li>id <%= i.id%></a> 
     <% end %> 
    </li> 
</ul> 

表:

<table class="table table-striped"> 
    <tbody> 
     <tr> 
     <th></th> 
     <th>First Name</th> 
     <th>Last Name</th> 
     <th>Age</th> 
     </tr> 
     <br> 
     <% @list[id].each do |u| %> 
     <tr> 
     <td> 
      <ul class="list green"> 
       <li><%=u.id%></li> 
      </ul> 
     </td> 
     <td><%=u.name%></td> 
     <td><%=u.name%></td> 
     <td><%=u.age%></td> 
     </tr> 
     <%end%> 
    </tbody> 
</table> 

我如何可以通過這個ID <li>id <%= i.id%></a>來這裏? <% @list[id].each do |u| %>

回答

0

你可以在ID添加到每個列表項如下:

<ul class="dropdown-menu dropdown-user users"> 
    <% @list.each do |i| %> 
    <li data-id="#{<%= i.id%>}"> 
    id <%= i.id%> 
    </li> 
    <% end %> 
</ul> 

然後也ID添加到每個行中的表和使用JavaScript來隱藏所有行,但有一個ID的一個匹配選定的ID:

<table class="table table-striped"> 
    <tbody> 
     <tr> 
     <th></th> 
     <th>First Name</th> 
     <th>Last Name</th> 
     <th>Age</th> 
     </tr> 
     <br> 
     <% @list.each do |i| %> 
     <% i.each do |u| %> 
     <tr data-id="#{<%= u.id%>}"> 
      <td> 
       <ul class="list green"> 
       <li><%=u.id%></li> 
       </ul> 
      </td> 
      <td><%=u.name%></td> 
      <td><%=u.name%></td> 
      <td><%=u.age%></td> 
     </tr> 
     <%end%> 
     <%end%> 
    </tbody> 
</table> 

或者你可以只使用ajax來更新表格。無論哪種方式將工作。

+0

沒有。下拉菜單和表格在@TinMonkey中 – dowatt

相關問題