Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 设置KeystoneJS日期格式_Javascript_Date_Format_Keystonejs - Fatal编程技术网

Javascript 设置KeystoneJS日期格式

Javascript 设置KeystoneJS日期格式,javascript,date,format,keystonejs,Javascript,Date,Format,Keystonejs,我似乎无法在keystone JS博客和其他页面上设置日期格式 如果我在模板中使用{{publishedDate}}(我使用的是车把),一切都很好,只是它给了我这样的信息:2017年3月23日星期四00:00:00 GMT+0000(GMT标准时间),这显然不好 {{ post.publishedDate.format('D MMMM') }} {{ post._.publishedDate.format('D MMMM') }} {{ publishedDate.format('D MMMM'

我似乎无法在keystone JS博客和其他页面上设置日期格式

如果我在模板中使用{{publishedDate}}(我使用的是车把),一切都很好,只是它给了我这样的信息:2017年3月23日星期四00:00:00 GMT+0000(GMT标准时间),这显然不好

{{ post.publishedDate.format('D MMMM') }}
{{ post._.publishedDate.format('D MMMM') }}
{{ publishedDate.format('D MMMM') }}
全部返回一个错误,如下所示: 第18行的分析错误: ... post.publishedDate.format('D MMMM')}< -----------------------^ 应为“ID”,但应为“无效”

我还尝试过改变模型中的内容:

publishedDate: { type: Types.Date, index: true, format: 'YYYY', dependsOn: { state: 'published' }},
及其众多变体。我已经查看了位于的keystone文档,并尝试实现其中所述内容,但仍然不起作用

这实际上应该很简单,我相信是的-我只是不知道怎么做(!)


感谢您的帮助。

下划线方法存在于文档中,而不是属性中。第二行代码应该可以工作;将使用所需格式格式化
publishedDate
项(如果不提供参数,则默认为
Do MMM YYYY
,但您可以通过向
format
提供参数来指定自己的矩.js格式)

只要将
post
作为局部变量提供给车把模板(
locals.post=post
在路线中),则不会返回任何错误

编辑2017年3月28日


在Handlebar中,您必须以不同于Keystone文档描述的方式向函数传递数据。他们使用帕格犬,所以你要做的事在帕格犬身上会起作用。车把对功能的评价不同。请尝试
{{post.\uu.publishedDate.format“D MMMM”}
“D MMMM”
字符串传递到format,然后它就可以正常工作了。

感谢Shea-职责范围之外的帮助。非常感谢;-)最终的解决方案(对于其他感兴趣的人)是——如果在循环中运行——在模型中创建一个虚拟对象,如下所示:

Post.schema.virtual('formattedDate').get(function () { 
    return this._.publishedDate.format("D MMMM"); 
});
然后,在把手模板中使用以下格式:

{{formattedDate}}
如果不在循环中运行,只需执行以下操作:


{{{.publishedDate.format“D MMMM”}

谢谢谢。。。在女朋友家的自动取款机上,远离个人电脑。星期二回到它,并将尝试实现这一点。再次干杯。嗯。。。不幸的是,我已经尝试过了,但没有产生任何效果。为了给你更多的上下文,在我的路线中有:var locals=res.locals;//Set locals.section='blog';locals.filters={post:req.params.post,};locals.data={posts:[],};post=post;在模板中,我有:{{post.\uu.publishedDate.format('D MMMM')}它仍然给我同样的错误-我缺少任何明显的错误?这可能与把手模板中的空格有关。试试
{{post.\uu.publishedDate.format('D MMMM')}}
不-已经试过了-我认为更基本的东西。。。我仔细检查了package.json和下划线,是否还有其他必要的内容?什么时候?没关系,算了吧!在Handlebar中,您必须以不同于Keystone文档描述的方式向函数传递数据。请尝试
{{post.\uu.publishedDate.format“D MMMM”}
“D MMMM”
字符串传递给
format
,然后它就可以正常工作了。
{{formattedDate}}