gpt4 book ai didi

coffeescript - Coffeescript 函数中的多行

转载 作者:行者123 更新时间:2023-12-05 01:36:31 27 4
gpt4 key购买 nike

我有以下 Coffeescript:

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

它转化为:
$(function() {
return $('#new_event').submit(function() {
$.post($(this).attr('action'), $(this).serialize(), function(data, textStatus, jqXHR) {
return $('#target').html(data);
});
return false;
});
});

到现在为止还挺好。但是,如何在提交中添加另一行?例如:
$ ->
$('#new_event').submit ->
test = $(this).serialize()
$.post(
$(this).attr('action')
$(this).serialize()
(data, textStatus, jqXHR) ->
$('#target').html(data)
)
return false

这会导致意外的 INDENT 错误。无法弄清楚我在这里错过了什么......

谢谢,
丹妮。

最佳答案

很可能你混合了空格和制表符来缩进。 Coffeescript 不喜欢那样。

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

关于coffeescript - Coffeescript 函数中的多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7991370/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com