Jade Mixin:500 TypeError:无法读取undefined的属性'length'

时间:2013-04-01 19:08:01

标签: node.js pug templating

我有一个混合因素给我带来了麻烦:

mixin dialog(title, description, choices)
    form.choices.dialog.row
        legend
            h1 #{title}
            p.description #{description}
        fieldset
            for choice in choices
                label
                    input(type= "radio", name = "choice.name", checked = "checked", required = "required")
                    | choice.name
        div.row.form-actions
            button(type="submit", ) Make Choice

要调用它,我首先将mixin文件包含在这个mixin中:

import dialog

然后我在创建一个javascript变量之后使用mixin:

- var investiageUFODialog = [{headerText: "Would you like to investiage the UFO?", description: "Choose whether or not to investigate the UFO."}, {choices: [{name: "Yes"}, {name: "No"}]}]

mixin dialog(investiageUFODialog.headerText, investiageUFODialog.description, investiageUFODialog.choices)

我做错了什么?

1 个答案:

答案 0 :(得分:3)

如果你想像这样使用它,那么

investiageUFODialog不能是一个数组。只需将其更改为:

- var investiageUFODialog = {headerText: "Would you like to investiage the UFO?", description: "Choose whether or not to investigate the UFO.", choices: [{name: "Yes"}, {name: "No"}]}

另外,在你的mixin中,你需要写name = choice.name(不带引号)。