我在生产中遇到了一些 JS 问题。这是我的 CoffeeScript:
$("form.edit_email_template").submit ->
window.onbeforeunload = -> null
$.each $("form.edit_email_template"), (i, v) ->
if CKEDITOR.instances[$("form.edit_email_template[action='" + $(v).attr("action") + "'] .email_content_area").attr("id")]
try
$.ajax($(v).attr("action"),
type: "POST"
data:
_method: "PUT"
authenticity_token: $("form.edit_email_template[action='" + $(v).attr("action") + "'] input[name='authenticity_token']").val()
email_template:
sendLength: $("form.edit_email_template[action='" + $(v).attr("action") + "'] #email_template_sendLength").val()
subject: $("form.edit_email_template[action='" + $(v).attr("action") + "'] #email_template_subject").val()
content: CKEDITOR.instances[$("form.edit_email_template[action='" + $(v).attr("action") + "'] .email_content_area").attr("id")].getData()
)
catch error
console.log(error)
在开发中,它可以完美运行。在生产中,我收到此错误:
Uncaught TypeError: Cannot call method 'getData' of undefined
我应该如何修复它?
CKEDITOR.instances => Object {et28: e, et31: e, et32: e, et36: e, et7: e…}
et: e
et7: e
et8: e
et24: e
et28: e
et31: e
et32: e
et36: e
所有的 DOM 元素都存在。如果我将 CoffeeScript 生成的 JS 粘贴到 JS 控制台中,它可以工作