[英]Append pug compiled Content to pug template
我們基於表生成輸入字段。 在這些過程中,標題(標題,單位)是恆定的,但是可能會有多個具有相同輸入類型的列(最簡單的是a,但是als可能是動態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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.