[英]Jade mixin attributes not applied
I'm using jade to template a report table as follows: 我正在使用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")
It's a nested mixin structure for a report row comprised of decorated report cells. 它是一个嵌套的mixin结构,用于包含装饰的报告单元格的报告行。
The problem is that the data-foo attribute is not being applied. 问题在于未应用data-foo属性。
I've seen other issues on SO about mixin attributes but I cannot find any syntax issue with the template, it just renders while ignoring the attributes. 我在SO上还看到了其他关于mixin属性的问题,但是我找不到模板的任何语法问题,它只是在忽略属性的同时进行渲染。
The documentation shows an example of passing attributes to mixins: 该文档显示了将属性传递给mixin的示例:
mixin link(href, name)
//- attributes == {class: "btn"}
a(class!=attributes.class, href=href)= name
+link('/foo', 'foo')(class="btn")
Notice that the mixin itself uses the implicit attributes
name to refer to the passed attributes - in other words, the attributes aren't auto-applied, they are just sent as arguments into the mixin. 请注意,mixin本身使用隐式
attributes
名称来引用传递的属性-换句话说,这些属性不会自动应用,它们只是作为参数发送到mixin中。 You'll have to change the definition of your cell_decorator
mixin to take the attributes into account. 您必须更改
cell_decorator
mixin的定义以考虑到属性。
If you want to simply apply the attributes on top of your mixin, you can use the &attributes
syntax: 如果您只想在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")
Note that using &attributes
like this (with a mixin call) is safe, as the values are escaped during the call. 注意,使用这样的
&attributes
(带有mixin调用)是安全的,因为在调用过程中会转义这些值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.