我正在尝试使用bootstrap-gallery在我的 Rails 4 应用程序中。
我遵循了简单的说明,但不理解其含义:
3. activate the plugin on the gallery container
$('.gallery').bootstrapGallery();
我尝试将其添加到我的 View 顶部:
<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
最佳答案
尝试:
$('.gallery').bootstrapGallery({});
出于某种原因,脚本期望将选项传递给它;如果您不需要更改任何内容,可以将选项设置为空。
关于javascript - bootstrap-gallery,激活画廊容器上的插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26288255/