【问题标题】:Coffee script compilation error咖啡脚本编译错误
【发布时间】:2013-07-02 17:40:25
【问题描述】:

这是我的咖啡,我根本不明白为什么这是错误的。我不断收到意外的错误。

renderTable:()=>
    @table = d3.select("#search-results-area").append("table").attr("id",@tableId).attr("class","visualization-panel")
    @thead = @table.append("thead")
    @tbody = @table.append("tbody")
    @input = @table.append("input").attr("id",@inputId).on("keydown",(d)=>
        console.log("keydown")
        console.log 
        toFilter = $(@input[0][0]).val() 
        window.setTimeout(()=> 
            toFilter = $(@input[0][0]).val() 
            @tbody.selectAll("tr")
        ,500)
    )

当我取出@tbody.selectAll("tr") 时,它起作用了,这让我感到困惑。

我该如何解决这个问题?

【问题讨论】:

    标签: javascript coffeescript


    【解决方案1】:

    我相信这与您定义window.setTimeout 部分的方式有关。由于缩进和括号,末尾的 ,500) 部分导致编译错误。尝试将该部分更改为:

    window.setTimeout ( ->
        toFilter = $(@input[0][0]).val() 
        @tbody.selectAll("tr")
    ), 500
    

    保持右括号缩进到与window 相同的位置。那应该可以修复编译。

    【讨论】:

      猜你喜欢
      • 2011-06-30
      • 2013-06-26
      • 2014-06-04
      • 2012-07-23
      • 2012-01-25
      • 2014-10-01
      • 2014-12-12
      • 2013-02-04
      • 1970-01-01
      相关资源
      最近更新 更多