gpt4 book ai didi

express - 在 Jade 中,为什么有时我可以按原样使用变量而有时必须将它们包含在#{......} 中?

转载 作者:行者123 更新时间:2023-12-02 03:29:44 25 4
gpt4 key购买 nike

看下面的代码

        for story in book 
if story.title.length < 140
- var storyTitle = story.title;
else
- var storyTitle = story.title.substring(0, 140) + '...';

.tiles
a(href= 'http://' + story.link)
img(src=story.thumbnail, width='150', height='150')
p Title: #{storyTitle}
p Date: #{story.time}
p Author: #{story.authorName}

这对我有用。然而让我感到困惑的是,有时我可以使用 story.attribute 而在某些地方我必须使用 #{story.attribute}。

例如。如果我使用这条线

p Title: storyTitle

没有 mustache ,它只是在浏览器中打印字符串“Title: storyTitle”。

另一个例子,如果我使用 img(src=#{story.thumbnail}, width='150', height='150'),它不起作用,我得到一个 html string (%20%20... something...) 在我的浏览器中。

那给了什么?

最佳答案

简单的说

After equal sign (=) and inside code blocks no curly braces. Everywhere else use #{}.

关于express - 在 Jade 中,为什么有时我可以按原样使用变量而有时必须将它们包含在#{......} 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14709560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com