0

所以我使用 mixin 在我的网络应用程序中显示一系列条目。我希望每个人都有一个相对时间戳,说明它是多久前发布的。

mixin listTitles(titles)
  each title in titles
     article.leaf
      article
    a.headline(href=title.URL)= title.title
  footer
    p.postData 
     | Posted 
     span#date=title.time
     a(href='someSource') The New York Times <br>
    a.commentButton(href=title.URL)
    a.sourceButton(href='#')
mixin listTitles(titles)

title.time 包含 javascript 时间的提交时间(以毫秒为单位的 unix 时间)。我想将其与当前时间进行比较并显示自提交帖子以来的时间。

4

1 回答 1

0

您可以在 Jade 模板中的任何地方使用 JS,方法是放置-在行首。

mixin listTitles(titles)
  - var now = Date.now();
  each title in titles
    p Posted #{now - title.time} millis ago.

我假设“没有 javascript”是指这个逻辑应该在模板本身而不是调用render().

于 2013-01-17T22:22:01.517 回答