【问题标题】:Accessing passed in variable to a mixin with Jade templates使用 Jade 模板访问传入的变量到 mixin
【发布时间】:2013-02-24 09:18:05
【问题描述】:

我有一个表单助手 mixin,我将一个变量传递给:

mixin form-error(error)
  if (typeof errors !== 'undefined' && errors.#{error})
    .alert.alert-error.form-error
      =errors.#{error}.msg

调用它并向它传递一个字符串:

mixin form_error('name')

但我得到了:500 SyntaxError: Unexpected token ILLEGAL

基本上我把所有东西都拿出来了,它对 errors.#{error}=errors.#{error}.msg 感到不安

所以我不能在. 之后使用#{error}

【问题讨论】:

    标签: javascript pug express


    【解决方案1】:

    你是这个意思吗?

    mixin form-error(error)
     if (typeof errors !== 'undefined' && errors[error])
      .alert.alert-error.form-error
       =errors[error].msg
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-04
      • 2014-11-30
      • 2013-04-06
      • 1970-01-01
      • 2016-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多