如何改变空格键输出的显示? [英] How to alter the display of what Spacebars outputs?

查看:62
本文介绍了如何改变空格键输出的显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在模板中有这样的东西:

So I have something like this in the template:

{{#each posts}}
    <li>{{date}}</li>
{{/each}}

这显示正常,但问题是我的日期"变量显示为 Sat Feb 07 2015 19:47:13 GMT-0800 (PST),这是准确但有点长和不必要的.

This displays fine, but the problem is that my "date" variable comes out as Sat Feb 07 2015 19:47:13 GMT-0800 (PST), which is accurate but kind of long and unneccessary.

我希望日期看起来更简单,比如 February 7, 2015.但是,请原谅我缺乏理解,但我知道如何做到这一点的唯一方法是开始以漂亮的格式存储它,但是如果我必须这样做,这似乎效率不高每次我想要看起来有点不同的东西.

I want the date to appear simpler, like February 7, 2015 instead. However, please forgive me for my lack of understanding, but the only way in which I know how to do this is to store it in the pretty format to begin with, but this doesn't seem to be efficient if I have to do this every time I want something to look a little different.

理想情况下,我想将其包装在 moment() 中并生成如下内容:

Ideally, I'd like to wrap it in a moment() and produce something like this:

moment(date).format("MMMM Do YYYY")

我尝试将其放入,但不起作用:

I tried putting in this instead, but it doesn't work:

{{#each posts}}
    <li>{{moment(date).format("MMMM Do YYYY")}}</li>
{{/each}}

推荐答案

添加助手

Template.yourTemplate.helpers({
  formattedDate: function(){
    return moment(this.date).format("MM/DD/YYYY");  // or whatever format you prefer
  }
});

这篇关于如何改变空格键输出的显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆