我们根据表格生成输入字段。在这些过程中,标题(标题,单位)不变,但可能有多个具有相同输入类型的列(最简单的是 a ,但也可能有动态 svgs),但内容不同。
我们希望动态生成 tds 内容并在渲染时将其附加到模板中。
模板的输入是:
[{RowId: 'bla', RowUnit: '-', RowField: pug.compile('input')},
{RowId: 'blub', RowUnit: 'm', RowField: pug.compile('span')}]
模板如下所示:
mixin addrow(rowdef)
tr(id= rowdef.RowId)
th= rowdef.RowId
td()
#{rowdef.RowField()}
th= "[" + rowdef.RowUnit + "]"
table(class="dialogcontents")
each rowdef in Contents
+addrow(rowdef)
button(class="okbtn") Ok
button(class="cancelbtn") Cancel
但上面的编译是这样的:
<table class="dialogcontents">
<tr id="bla">
<th>bla</th>
<td><<input/>></<input/>></td>
^--- It looks like the tagname is "<input/>", so the function is compiled and applied as string then
<th>[-]</th>
</tr>
<tr id="blub">
<th>blub</th>
<td><<span></span>></<span></span>></td>
^--- as above
<th>[m]</th>
</tr>
</table>
<button class="okbtn">Ok</button>
<button class="cancelbtn">Cancel</button>
总而言之,编译的函数似乎被调用了两次。我可以请教一下吗?
我不确定你更广泛的目标是什么,但如果你想使用在本地定义的标签,你可以设置RowField: 'span'
然后使用标签插值:
#{rowdef.RowField} This is my span.
这将呈现:
<span>This is my span.</span>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句