将此代码放入clients.js.coffee并刷新我的浏览器后没有任何反应,然后我重新启动本地服务器,也没有发生任何事情,我该怎么办?
clients.js.coffee
jQuery ->
$('#client_street_id').parent().hide()
street = $('#client_street_id').html()
$('#client_city_id').change ->
city = $('#client_city_id :selected').text()
escaped_city = city.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1')
options = $(street).filter("optgroup[label='#{escaped_city}']").html()
if options
$('#client_street_id').html(options)
$('#client_street_id').parent().show()
else
$('#client_street_id').empty()
$('#client_street_id').parent().hide()
的application.js
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require_tree .
答案 0 :(得分:1)
固定缩进。
每个 - >应该跟随2个空格缩进,直到你想要关闭该功能。
基本转换http://js2coffee.org/(仅为了给您一个想法)
jQuery ->
$('#client_street_id').parent().hide()
street = $('#client_street_id').html()
$('#client_city_id').change ->
city = $('#client_city_id :selected').text()
escaped_city = city.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1')
options = $(street).filter("optgroup[label='#{escaped_city}']").html()
if options
$('#client_street_id').html(options)
$('#client_street_id').parent().show()
else
$('#client_street_id').empty()
$('#client_street_id').parent().hide()