Rails Rails 中的 JS 加载问题 (KO)

flowerwrong · 2014年07月13日 · 最后由 flowerwrong 回复于 2014年07月14日 · 2348 次阅读

在前台我所有的 js 文件都压缩在了 frontend.js 里面,其中包括一个首页幻灯片的滑块文件。 http://workshop.rs/projects/coin-slider/ 问题是加载首页的时候第一次加载进去没问题,点击其他菜单,在点击回到首页的时候幻灯片就不工作了,右键刷新又可以了。 我确定不是 js 本身的问题,是加载的问题。 操作步骤:先点击除首页意外的其他任意菜单,然后再点击首页,就可以看到问题了。然后右键刷新,有正常工作。 感谢 rei,已解决。<a href="..." data-no-turbolink>No turbolinks here</a>

1.gem 'turbolinks'
2.//= require turbolinks
3.
$(document).on 'click', '.edit_task input[type=checkbox]', ->
  $(this).parent('form').submit()

# alternatively:

ready = ->
  $(document).on 'click', '.edit_task input[type=checkbox]', ->
    $(this).parent('form').submit()

$(document).ready(ready)
$(document).on('page:load', ready)

or
$(document).on 'ready page:load', ->
  $(document).on 'click', '.edit_task input[type=checkbox]', ->
    $(this).parent('form').submit()

Turbolinks

#1 楼 @Rei thx just add <a href="..." data-no-turbolink>No turbolinks here</a>

@Rei data-no-turbolink 在标签中是什么作用啊?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号