【问题标题】:Jade Mixin: 500 TypeError: Cannot read property 'length' of undefinedJade Mixin:500 TypeError:无法读取未定义的属性“长度”
【发布时间】:2013-04-01 19:08:01
【问题描述】:

我有一个 mixin 给我带来了麻烦:

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

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

- 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)

我做错了什么?

【问题讨论】:

    标签: node.js pug templating


    【解决方案1】:

    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(不带引号)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-12
      • 1970-01-01
      • 1970-01-01
      • 2021-12-05
      • 2020-07-20
      • 2020-03-07
      相关资源
      最近更新 更多