简体   繁体   中英

Coffeescript gives “Uncaught TypeError: makesSelect is not a function” on passed argument

So i have this coffeescript

dynamicSelect = (makesSelect) ->
  $(document).on 'change', makesSelect, (evt) ->
    $.ajax 'update_make_models',
      type: 'GET'
      dataType: 'script'
      data: {
        make_id: $(makesSelect 'option:selected').val()
      }
      error: (jqXHR, textStatus, errorThrown) ->
        console.log("AJAX Error: #{textStatus}")
      success: (data, textStatus, jqXHR) ->
        console.log("Dynamic make select OK!")

  dynamicSelect '#diy_attached_vehicles_attributes_0_make'

which gives me this error

Uncaught TypeError: makesSelect is not a function

It's this line which causes it

make_id: $(makesSelect 'option:selected').val()

So how should i pass "makesSelect" correctly, in anonymous function it should look like this(tested and works)

make_id: $('#diy_attached_vehicles_attributes_0_make option:selected').val()

尝试这个:

make_id: $("#{makesSelect} option:selected").val()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM