0

我有以下咖啡脚本:

  $("#complete").click ->
    bootbox.dialog "Remember, if you complete the workorder you won't be able to add labor and materials.", [
      label: "Complete"
      class: "btn-success"
      callback: ->
        $("td").filter(':contains("ID:")').each ->
          woid = $(this).nextAll().text()
        $.update "/workorders/" + woid,
         workorder:
           wostatus_id: 232
    ,
     label: "Cancel"
      class: "btn-danger"
      callback: ->
        return 'false'
    ]

当它运行时,我在浏览器控制台中得到这个:

Uncaught ReferenceError: woid is not defined 

谢谢您的帮助!

4

1 回答 1

1

变量的范围仅限于您首次分配给它们的函数。要使其woid可用,请将其初始化为null您的过滤器回调之外:

    woid = null

    $("td").filter(':contains("ID:")').each ->
      woid = $(this).nextAll().text()
    $.update "/workorders/" + woid,
     workorder:
       wostatus_id: 232

和往常一样,在调试时检查你编译的 JavaScript。答案通常很明显。

于 2013-07-02T17:55:44.530 回答