繁体   English   中英

Jade mixin属性未应用

[英]Jade mixin attributes not applied

我正在使用jade将报告表模板化,如下所示:

mixin report_row(row)
  tr(data-id=row.c[keyIndex].v)
    each cell, i in row.c
      +cell_decorator(data.cols[i], cell)(data-foo="bar")

它是一个嵌套的mixin结构,用于包含装饰的报告单元格的报告行。

问题在于未应用data-foo属性。

我在SO上还看到了其他关于mixin属性的问题,但是我找不到模板的任何语法问题,它只是在忽略属性的同时进行渲染。

文档显示了将属性传递给mixin的示例:

mixin link(href, name)
  //- attributes == {class: "btn"}
  a(class!=attributes.class, href=href)= name

+link('/foo', 'foo')(class="btn")

请注意,mixin本身使用隐式attributes名称来引用传递的属性-换句话说,这些属性不会自动应用,它们只是作为参数发送到mixin中。 您必须更改cell_decorator mixin的定义以考虑到属性。

如果您只想在mixin之上应用属性,则可以使用&attributes语法:

mixin cell_decorator(colname, data)
    //- the `attributes` get applied to the td
    td(...)&attributes(attributes)

+cell_decorator(data.cols[i], cell)(data-foo="bar")

注意,使用这样的&attributes (带有mixin调用)是安全的,因为在调用过程中会转义这些值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM