简体   繁体   English

Coffeescript在传递的参数上给出“未捕获的TypeError:makeSelect不是函数”

[英]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 未捕获的TypeError:makesSelect不是函数

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) 因此,我应该如何正确传递“ makesSelect”,在匿名函数中,它应该看起来像这样(经过测试并可以工作)

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

尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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