如何使这个CoffeeScript TurboLinks 5的代码段友好? [英] How do I make this snippet of CoffeeScript TurboLinks 5 friendly?

查看:178
本文介绍了如何使这个CoffeeScript TurboLinks 5的代码段友好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下:

$ ->
    $('[data-provider="summernote"]').each ->
      $(this).summernote
        height: 300

所以我尝试了以下操作:

So I tried the following:

$ ->
  ready = ->
    $('data-provider="summernote"]').each ->
      $(this).summernote
        height: 300

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

但我一直收到此错误:

Uncaught ReferenceError: ready is not defined

顺便说一句,我在我的 jobs.coffee 文件中,这是我知道是包括在我的资产管道。

By the way, I am doing this in my jobs.coffee file, which I know is being included in my asset-pipeline. So that's not it.

推荐答案

在Rails 5(Turbolinks 5), turbolinks:load

In Rails 5 (Turbolinks 5), turbolinks:load. Also, you don't need to wrap your event handlers into the "document ready".

将您的代码重写为:

ready = ->
  $('data-provider="summernote"]').each ->
    $(this).summernote(height: 300)

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

这篇关于如何使这个CoffeeScript TurboLinks 5的代码段友好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆