ere*_*ere 1 javascript arrays if-statement coffeescript
在咖啡脚本中,我试图弄清楚数组中是否包含某些内容.但似乎无法弄清楚正确的语法.有没有办法做到这一点,而不必迭代它们?
谢谢,
if $(this).val() is in ["needs_cover","comatose"]
$("#head_count").hide()
else
$("#head_count").show()
Run Code Online (Sandbox Code Playgroud)
只需删除is
:
if $(this).val() in ["needs_cover","comatose"]
$("#head_count").hide()
else
$("#head_count").show()
Run Code Online (Sandbox Code Playgroud)
这将转换为以下JavaScript:
var _ref;
if ((_ref = $(this).val()) === "needs_cover" || _ref === "comatose") {
$("#head_count").hide();
} else {
$("#head_count").show();
}
Run Code Online (Sandbox Code Playgroud)