在哈巴狗模板中,我尝试使用下面的代码块从错误数组(如果已定义)中打印所有错误:
if errors !== "undefined"
each item in errors
.msgError Error:
= item.msg
else
div success!
如果定义了数组“ errors”,它将按预期工作。但是,我不知道为什么即使未定义数组“ errors”,它仍然进入true分支并打印该数组的项,然后得到此信息:
messages.pug:2 1| if errors !== "undefined" > 2| each item in errors 3| .msgError Error: 4| = item.msg 5| else Cannot read property 'length' of undefined
如果我将其编写为像这样的多行javascript块:
-
if errors !== "undefined"
each item in errors
.msgError Error:
= item.msg
else
console.log(errors)
我收到此错误:
Unexpected token (106:3)
SyntaxError: Unexpected token (106:3)
请告知。谢谢。
删除未定义的引号。