引导库,激活库容器上的插件

bootstrap-gallery, activating plugin on gallery container

本文关键字:插件 激活      更新时间:2023-09-26

我正试图在rails 4应用程序中使用引导库。

除了不理解的含义之外,我遵循了简单的说明

3.  activate the plugin on the gallery container
$('.gallery').bootstrapGallery();

我试图用将其添加到我的视图顶部

<script>
$('.gallery').bootstrapGallery();
</script>

但是当我点击图像时,JS似乎不会执行(我只是被带到图像URL),我在JS控制台中得到以下错误:

Uncaught TypeError: Cannot call method 'hasOwnProperty' of undefined
Uncaught TypeError: Cannot call method 'addMarker' of undefined

我哪里出错了?

编辑:这就是我的观点:

<%= javascript_include_tag "bootstrap-gallery" %>
<%= stylesheet_link_tag "bootstrap-gallery" %>
<div class="gallery row">
  <% @post.assets.each do |asset| %>
     <a class="col-xs-6 col-sm-4" href=<%= asset.asset.url(:medium) %>>
       <img src=<%= asset.asset.url(:medium) %> alt="">
     </a>
  <% end %>
</div>
<script>
var ready;
ready = function() {
  $('.gallery').bootstrapGallery();
};
$(document).ready(ready);
$(document).on('page:load', ready);
</script>

仍然遇到相同的问题:

Uncaught TypeError: Cannot call method 'hasOwnProperty' of undefined

try:

$('.gallery').bootstrapGallery({});

出于某种原因,脚本期望将选项传递给它;如果不需要更改任何内容,可以将选项设置为空。