Coffeescript函数中的多行

cod*_*dog 4 coffeescript

我有以下Coffeescript:

$ ->
    $('#new_event').submit ->
        $.post(
            $(this).attr('action')
            $(this).serialize()
            (data, textStatus, jqXHR) ->
                $('#target').html(data)
        )
        return false
Run Code Online (Sandbox Code Playgroud)

它转化为:

$(function() {
  return $('#new_event').submit(function() {
    $.post($(this).attr('action'), $(this).serialize(), function(data, textStatus, jqXHR) {
      return $('#target').html(data);
    });
    return false;
  });
});
Run Code Online (Sandbox Code Playgroud)

到现在为止还挺好.但是,如何在提交中添加另一行?例如:

$ ->
    $('#new_event').submit ->
        test = $(this).serialize()
        $.post(
            $(this).attr('action')
            $(this).serialize()
            (data, textStatus, jqXHR) ->
                $('#target').html(data)
        )
        return false
Run Code Online (Sandbox Code Playgroud)

这会产生意外的INDENT错误.无法弄清楚我在这里失踪了什么......

谢谢,丹妮.

Thi*_*ilo 5

最有可能的是混合空格和制表符以进行缩进.Coffeescript不喜欢这样.

顺便说一句,你可以写@而不是this.