CoffeeScript - 无与伦比的 OUTDENT [英] CoffeeScript - Unmatched OUTDENT

查看:29
本文介绍了CoffeeScript - 无与伦比的 OUTDENT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将我的工作 javascript 代码传递给 CoffeeScript,但我无法通过此错误:

I've been trying to pass my working javascript code into CoffeeScript but i can't get pass this error:

第 55 行不匹配的 OUTDENT

unmatched OUTDENT on line 55

这是咖啡脚本代码

$(document).on("click",".save_button", ->
    $form = $(this).parent().parent().parent().parent().parent().parent()
    $form.bind("ajax:complete", ->
                $actionURI = $form.attr("action");
        $.get(window.location.protocol+"//"+window.location.host+$actionURI+".js",(data) ->
                    $form.parent().parent().prev().html(data); //Line 55
                    closeSaveElement()
        ,"html")
    );
    $form.submit();   
    return false;
);

我已经尝试在任何地方放置和擦除 ; 但我没有什么问题.我也尝试将 -> 更改为 => 但弹出相同的错误.

i've tried putting and erasing ; everywhere but i don't whats wrong. I also tried to change -> for => but the same error pops up.

推荐答案

有效的 JS 并不是真正有效的 CoffeeScript.你必须这样做:

Valid JS isn't really valid CoffeeScript. You'd have to do something like this:

$(document).on "click", ".save_button", ->
    $form = $(this).parent().parent().parent().parent().parent().parent()

    $form.bind "ajax:complete", ->
        $actionURI = $form.attr "action"
        $.ajax
            type: "get"
            url: "#{window.location.protocol}//#{window.location.host}#{$actionURI}.js"
            dataType: "html"
            success: ->
                $form.parent().parent().prev().html(data)
                closeSaveElement()

    $form.submit()

    return false

另外,对这一行做点什么:

Also, do something about this line:

$form = $(this).parent().parent().parent().parent().parent().parent()

.closest() 应该会有所帮助.

这篇关于CoffeeScript - 无与伦比的 OUTDENT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆