将 pug 编译的内容附加到 pug 模板
Append pug compiled Content to pug template
我们根据表格生成输入字段。在这些过程中 headers (title, unit) 常量,但可能有多个具有相同输入类型的列(最简单的是 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>
我们根据表格生成输入字段。在这些过程中 headers (title, unit) 常量,但可能有多个具有相同输入类型的列(最简单的是 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>