请看下面的代码
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}这对我很有效。然而,令我困惑的是,在tmes中,我可以使用story.attribute,而在某些地方,我必须使用#{story.attribute}。
例如。如果我用这行
p Title: storyTitle如果没有鼠标,它只需在浏览器中打印字符串"Title: storyTitle“。
另一个例子是,如果我使用img(src=#{story.thumbnail}, width='150', height='150'),它不工作并且我得到一个html字符串(%20%20...某件事...)在我的浏览器里。
那是怎么回事呢?
发布于 2013-02-06 05:33:50
简单地说
等号(=)和内部代码后面的
不会阻止大括号。在其他地方使用
#{}。
发布于 2013-02-06 01:52:26
区别在于标签的内容和属性。在属性中,可以使用不带大括号的变量,如
img(src=story.thumbnail因为您不能只将文本放在属性的值中,所以它必须是一个字符串:
img(src="/images/story.jpg")你不能就这么做
img(src=/images/story.jpg)但是在标记的内容中,您必须使用hash+braces #{},以便Jade知道哪些位是变量,哪些位只是文本。
如果你想在标签属性中使用hash+braces,你可以这样做:
img(src="#{story.thumbnail}")https://stackoverflow.com/questions/14709560
复制相似问题