2016-06-16 20 views
1

我有一個表,我用最好的地方來更新項目。表中的每個項目都具有該表單元素,並且它們全都具有相同的ID。所以當我們更新一個元素的屬性時,所有的元素都將被更新爲相同的數據。 我如何解決這個問題。任何幫助,將不勝感激。由於獲取在表中的表單元素在軌道上的唯一ID

表的結構:

<table class="table table-striped table-bordered" id="spare_table"> 
     <thead> 
    <tr> 
     <th>Name</th> 
     <th> Price </th> 
     <th>Actions</th> 
    </tr> 
    </thead> 

    <tbody> 
    <% @manufacturer.spares.each_with_index do |spare, index| %> 
     <tr id="li_<%= spare.id.to_s %>"> 
     <td><%= spare.name %></td> 
     <td> 
     <button type="button" class="btn btn-warning btn-xs" data-toggle="modal" data-target="#myModal2" id="add"> 
          Show 
          </button> 
    <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> 
    <div class="modal-dialog" role="document"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
     <h4 class="modal-title" id="myModalLabel"><%= spare.name%></h4> 

     </div> 
     <div class="modal-body"> 
     <b> Name : </b> <%= spare.name %> <br/> <br/> 
     ... 
     <% end %> 

     </ul> 
     </div> 
     <div class="modal-footer"> 
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 

我已經更新表的結構。這裏即時顯示模式內的細節,但所有的備件將具有第一個備件本身的細節

+0

ID必須是唯一的..爲什麼所有這些元素都有相同的ID? – pumpkinzzz

回答

0

向我們展示表格的結構和一對值以檢查是否有一些可以使用的唯一值檢查以確定。也許這個名字是獨一無二的?

您總是需要找到一個具有非重複值的鍵來標識表格的一行。

+0

嘿,我有問題 –

+0

更新我指表作爲數據庫表:) 關於你的代碼你的業餘時間有: spare.name spare.id 所以,如果ID重複識別的唯一途徑是按名稱 –

+0

嘿,我意味着java腳本ID? 。對於每一行我正在更新數量,並且由於所有表單元素將在同一頁面上,因此所有表單元素都將使用相同的值進行更新。 –