首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在.each循环- Rails / Bootstrap中显示一个条目的模式

在.each循环- Rails / Bootstrap中显示一个条目的模式
EN

Stack Overflow用户
提问于 2015-04-19 23:42:14
回答 1查看 4.4K关注 0票数 3

我想要一个链接来打开一个显示单击对象(word.title)的模式,显示在每个循环中。现在,它打开模式,但随后再次显示循环中的每一项。

代码语言:javascript
运行
复制
    <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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-20 00:18:55

要使链接调用正确的模式,需要将id分配给每个modals。并使用data-target属性通过将id of modal传递给它来调用一个模式。

你的代码看起来可能是这样的。

代码语言:javascript
运行
复制
<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

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29737201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档