我们基于表格生成输入字段。在这些过程中,标题(title,unit)不变,但可能有多个列具有相同的输入类型(最简单的是a,但也可能有动态svg),但内容会有所不同。
我们希望动态生成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>总而言之,编译后的函数似乎被调用了两次。我可以请教一下吗?
发布于 2019-08-07 05:21:07
我不确定您更广泛的目标是什么,但如果您想使用在本地变量中定义的标记,您可以设置RowField: 'span',然后使用标记插值:
#{rowdef.RowField} This is my span.这将呈现:
<span>This is my span.</span>https://stackoverflow.com/questions/57369614
复制相似问题