我想要一个链接来打开一个显示单击对象(word.title)的模式,显示在每个循环中。现在,它打开模式,但随后再次显示循环中的每一项。
<h1>Glossary of words</h1>
<p>Pagination at 25</p>
<table class="table table-hover">
<thead>
<tr>
<th>Title</th>
<th>Definition</th>
<th>Usage</th>
<th>Word Type</th>
</tr>
</thead>
<tbody>
<% @words.each do |word| %>
<tr>
<th scope="row">
<a href="#" data-toggle="modal" data-target=".bs-example-modal-sm">
<%= word.title %>
</a>
<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<%= word.title %>
</div>
</div>
</div>
</th>
<td><%= word.title %></td>
<td><%= word.definition %></td>
<td><%= word.word_type %></td>
</tr>
<% end %>
</tbody>
</table>
// Word Modal
$('.bs-example-modal-sm').modal()发布于 2015-04-20 00:18:55
要使链接调用正确的模式,需要将id分配给每个modals。并使用data-target属性通过将id of modal传递给它来调用一个模式。
你的代码看起来可能是这样的。
<a href="#" data-toggle="modal" data-target="#modal-<%= word.id %>">
<%= word.title %>
</a>
<div id="modal-<%= word.id %>" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<%= word.title %>
</div>
</div>
</div>来源:http://getbootstrap.com/javascript/#live-demo
https://stackoverflow.com/questions/29737201
复制相似问题