Node JS Pug模板循环错误

问题描述 投票:0回答:1

在哈巴狗模板中,我尝试使用下面的代码块从错误数组(如果已定义)中打印所有错误:

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)

请告知。谢谢。

javascript node.js pug ejs
1个回答
0
投票

删除未定义的引号。

© www.soinside.com 2019 - 2024. All rights reserved.