Javascript 未应用Jade mixin属性
我正在使用jade为报表表创建模板,如下所示:Javascript 未应用Jade mixin属性,javascript,pug,Javascript,Pug,我正在使用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结构,用于由修饰的报表单元格组成的报表行 问题是没有应用数据foo属性 我已经看到了关于mixin属性的其他问题,但是我找不到该模板的任何语法问题,它
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结构,用于由修饰的报表单元格组成的报表行
问题是没有应用数据foo属性
我已经看到了关于mixin属性的其他问题,但是我找不到该模板的任何语法问题,它只是在忽略属性的情况下进行渲染。显示了将属性传递给mixin的示例:
mixin link(href, name)
//- attributes == {class: "btn"}
a(class!=attributes.class, href=href)= name
+link('/foo', 'foo')(class="btn")
注意,mixin本身使用隐式的属性
名称来引用传递的属性——换句话说,属性不是自动应用的,它们只是作为参数发送到mixin中。您必须更改cell\u decorator
mixin的定义,以将属性考虑在内
如果只想在mixin上应用属性,可以使用以下语法:
请注意,像这样使用
&attributes
是安全的(使用mixin调用),因为在调用过程中会转义值。你完全正确,我完全错过了attribute应用程序。谢谢@voithos!
mixin cell_decorator(colname, data)
//- the `attributes` get applied to the td
td(...)&attributes(attributes)
+cell_decorator(data.cols[i], cell)(data-foo="bar")