私はアイテムを更新するのに最適な場所にテーブルを持っています。テーブル内のすべてのアイテムはそのフォーム要素を持ち、すべてが同じ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">×</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>
私は、テーブルの構造を更新しました。ここでモーダル内の詳細を表示していますが、すべてのスペアには最初のスペアの詳細が表示されます
IDは一意である必要があります。なぜこれらの要素はすべて同じIDですか? – pumpkinzzz