【问题标题】:How Do I Implement a Popover in a Rails Partial Using Bootstrap 3?如何使用 Bootstrap 3 在 Rails Partial 中实现弹出框?
【发布时间】:2016-10-11 12:12:47
【问题描述】:

我目前有一个运行 Bootstrap 2 的 Rails 4 应用程序(gem twitter-bootstrap-rails 2.2.8)。我成功地使用部分实现了弹出框,单击链接时会显示地图。这是我的代码。

应用程序.js

//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require_tree .

bootstrap.js.coffee

jQuery ->
  $(".popover-map").popover({ html : true })

_地图

<div class="row-fluid">
  <div class="span4" align="center" id="text-bold"><%= link_to("#{t :map_marfa_head}" , '#', class: "popover-map", rel: "popover", title: "#{t :map_marfa_head}", :"data-placement" => "bottom", :"data-content" => "#{render 'pages/map_marfa'}") %></div>
  <div class="span4" align="center" id="text-85"><%= "#{t :map_msg_click}" %></div>
  <div class="span4" align="center" id="text-bold"><%= link_to("#{t :map_bigbend_head}" , '#', class: "popover-map", rel: "popover", title: "#{t :map_bigbend_head}", :"data-placement" => "bottom", :"data-content" => "#{render 'pages/map_bigbend'}") %></div>
</div>

_map_marfa

<p align="center"><%= image_tag("map-marfa.jpg", alt: "#{t :map_marfa_head}") %></p>

_map_bigbend

<p align="center"><%= image_tag("map-bigbend.jpg", alt: "#{t :map_bigbend_head}") %></p>

当我单击任一链接时,地图会显示在下方并停留在那里,直到该人再次单击该链接以关闭地图。我已将代码复制到我的新 Rails 5 Bootstrap 3 应用程序中。以下是 Bootstrap 3 的代码更改。

应用程序.js

//= require bootstrap-sprockets

bootstrap.js.coffee 被重命名为 bootstrap.coffee

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
//= require bootstrap-sprockets

_地图

<div class="row">
  <div class="col-md-4" align="center" id="text-bold"><%= link_to("#{t :map_marfa_head}" , '#', class: "popover-map", rel: "popover", title: "#{t :map_marfa_head}", :"data-placement" => "bottom", :"data-content" => "#{render 'pages/map_marfa'}") %></div>
  <div class="col-md-4" align="center" id="text-85"><%= "#{t :map_msg_click}" %></div>
  <div class="col-md-4" align="center" id="text-bold"><%= link_to("#{t :map_bigbend_head}" , '#', class: "popover-map", rel: "popover", title: "#{t :map_bigbend_head}", :"data-placement" => "bottom", :"data-content" => "#{render 'pages/map_bigbend'}") %></div>
</div>

现在,当我单击任一链接时,地图会显示并立即消失,而不是一直停留到单击链接为止。

【问题讨论】:

    标签: jquery ruby-on-rails twitter-bootstrap twitter-bootstrap-3 twitter-bootstrap-2


    【解决方案1】:

    我一直在看这个并意识到在application.js 我需要turbolinks。无论出于何种原因,它都会打乱我尝试做的事情。我删除了//= require turbolinks,我的脚本又可以工作了。去图吧。

    【讨论】:

    • 不幸的是,我又遇到了这个问题。在 Rails 5.0.2 和 bootstrap-sass 3.1.7 中运行相同的逻辑,我的地图不再工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-25
    • 2016-02-11
    • 2014-12-31
    • 2011-06-16
    • 1970-01-01
    • 2019-03-06
    相关资源
    最近更新 更多