当我需要在JS中使用一个类似JSON的对象,在每个块中使用不同的数据并迭代该对象时,我会通过pug生成HTML代码。
让我用代码来描述它
var footerMenu = {
left: {
title: "sometitle",
list: [
{
title: "First thing to do",
text: "wake up and brush some teeth"
},
{
title: "Second thing to do",
text: "start coding"
},
(...)当带有footerMenu.left[0].text属性的文本必须使用一些标记来设置样式时,问题就来了。
我需要这样的东西
...... text: "wake up and #[span.color-red brush] some teeth"但是,当然,帕格将其理解为简单的字符串。
我不想手动编写每个代码块,如何保存相同的代码结构并使用pug将随机标记应用到我的JSON-object中?
发布于 2019-04-22 20:57:15
您可以编写html标记,通常如下所示:
text: "wake up and <span class='color-red brush'>some teeth</span>"
然后在pug中,你可以像这样使用unescaped attributes:
.some-class!=footerMenu.left[0].text或者使用string interpolation attributes unescaped
.some-class !{footerMenu.left[0].text}https://stackoverflow.com/questions/55794423
复制相似问题