【发布时间】:2017-02-25 16:24:40
【问题描述】:
这似乎没有加载到我的侧边栏。我认为这与 rails 4 中的 Turbolinks 有关,因为如果我重新加载页面,它似乎可以工作。关于如何更改它以使其正常工作的任何想法?
jQuery ->
category = $('#subject_category').html()
$('#subject_product').change ->
product = $('#subject_product :selected').text()
escaped_product = product.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1')
options = $(category).filter("optgroup[label='#{escaped_product}']").html()
if options
$('#subject_category').html(options)
$('#subject_category').parent().show()
else
$('#subject_category').empty()
$('#subject_category').parent().hide()
$ ->
category = $('#sidebar .category_select').html()
options = $(category).filter("optgroup[label='Car']").html()
if options
$('#sidebar .category_select').html(options)
$('#sidebar .category_select').parent().show()
else
$('#sidebar .category_select').empty()
$('#sidebar .category_select').parent().hide()
【问题讨论】:
-
我的问题是咖啡脚本语法,不确定其他帖子是否解决了我的请求。因为这些不是加载事件
-
$ ->是jQuery ->的快捷方式,这是document ready的快捷方式。这篇文章描述了document ready与 turbolinks 的不同之处,我相信这是你的问题。 -
所以我应该用
$(document).on "turbolinks:load", ->替换$ ->,这样对吗?jQuery ->的捷径是什么?我是否也应该将jQuery ->替换为$(document).on "turbolinks:load", ->?
标签: jquery ruby-on-rails ruby-on-rails-4 coffeescript