从coffeescript编译的jquery代码中未捕获的ReferenceError

时间:2014-10-16 02:17:38

标签: javascript jquery coffeescript referenceerror

我有以下jquery代码(从coffee脚本编译)。

(function() {
  $(function() {
    return $.get('/proteins', function(proteins) {});
  });
  $.each(proteins, function(index, protein) {
    return $('#proteins').append($("<li>").text(protein.name));
  });
}).call(this);

生成此代码的coffeescript如下所示:

$ ->
  $.get '/proteins', (proteins) ->
    $.each proteins, (index, protein) ->
     $('#proteins').append $("<li>").text protein.name

我一直得到一个&#34;未捕获的ReferenceError:未定义蛋白质&#34;在我生成的代码的第6行。

我在这里遗漏了什么(非常基本的)?

谢谢!

1 个答案:

答案 0 :(得分:0)

在其他位置有一个缩进$ .each和空格的制表符。缩进不正确。使用带有coffeescript支持的编辑器。