Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 控制台中出现Coffescript错误:未捕获类型错误:对象不是函数_Jquery_Ruby On Rails_Coffeescript - Fatal编程技术网

Jquery 控制台中出现Coffescript错误:未捕获类型错误:对象不是函数

Jquery 控制台中出现Coffescript错误:未捕获类型错误:对象不是函数,jquery,ruby-on-rails,coffeescript,Jquery,Ruby On Rails,Coffeescript,在rails应用程序上工作,我的coffeescript代码被破坏。 $('.post-reply4').hide() 他在工作,但别的什么都没有。点击message4链接没有任何作用 控制台给出了这个错误:uncaughttypeerror:object不是函数 共同脚本: # Place all the behaviors and hooks related to the matching controller here. # All this logic will automatica

在rails应用程序上工作,我的coffeescript代码被破坏。

$('.post-reply4').hide() 
他在工作,但别的什么都没有。点击message4链接没有任何作用

控制台给出了这个错误:uncaughttypeerror:object不是函数

共同脚本:

# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

jQuery ->

    toggleThis = () ->
        $('#post-reply4').show()

    $('.post-reply4').hide()

    $('#message4').on('click') ->
        toggleThis
html:


您的coffescript函数声明应为:

toggleThis = ->
    $('.post-reply4').show()
那么你的电话应该是:

$('#message4').on 'click', (evt) ->
    toggleThis() 
有关语法,请参阅此“”


更新:感谢@muistooshort,他在下面的评论中指出,当您应该使用类选择器时,您正在使用id选择器“#post-reply4”。上面的代码中更新了post-reply4。

您可以发布生成的javascript吗?在#message4:
$(“#message4')的点击事件中调用toggleThis时,请尝试添加括号。('Click')on('Click'))->toggleThis()
嘿,谢谢@vinodadhikary。但是当我点击message4时,post-reply4并没有显示出来。这就是它在js中编译成的函数(function(){jQuery(function(){var toggleThis;$('.post-reply4').hide();toggleThis=function(){return$('.#post-reply4').toggle();};return$('.#message4')。on('click',function(evt){return toggleThis()});})。调用(This);为什么只需
(evt)->切换此()
$(…)。在“单击”时,切换此就可以了?@PavanKatepalli:您的类和id选择器似乎有点混淆。@muistooshort非常感谢您!真不敢相信我错过了!
toggleThis = ->
    $('.post-reply4').show()
$('#message4').on 'click', (evt) ->
    toggleThis()