1

将此代码放入clients.js.coffee并刷新浏览器后没有任何反应,然后我由本地服务器重新启动,也没有任何反应,我该怎么办?

客户.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()

应用程序.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 .
4

1 回答 1

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()
于 2013-05-05T15:22:41.170 回答