[英]Can I create dynamic variable names in jade using an array of string values for an object?
[英]Dynamic element in Jade with String and a variable
我有一個變量,例如名為“ elem”,“ elem”可以是頭部,身體和腳;
我想用例如創建html元素;
if elem == "body"
"t" + elem => tbody html element
if elem == "head"
"t" + elem => thead html element
if elem == "foot"
"t" + elem => tfoot element
我嘗試了許多組合,但未能做到這一點。 如何實施這種情況?
嘗試這樣的事情(在這種情況下,我假設elem = "foot"
):
- var tag = "t" + elem;
table
thead
tbody
#{tag}
應該呈現:
<table>
<thead></thead>
<tbody></tbody>
<tfoot></tfoot>
</table>
但是請記住,此表不是html符合。 這只是為了演示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.