Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.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 无法格式化keystone.js中的嵌套日期字段_Javascript_Underscore.js_Momentjs_Swig Template_Keystonejs - Fatal编程技术网

Javascript 无法格式化keystone.js中的嵌套日期字段

Javascript 无法格式化keystone.js中的嵌套日期字段,javascript,underscore.js,momentjs,swig-template,keystonejs,Javascript,Underscore.js,Momentjs,Swig Template,Keystonejs,我正在扩展keystone.js以支持模型中的多种语言 原始模型如下所示: Post.add({ title: { type: String, required: true }, publishedDate: { type: Types.Date, index: true }, //... more irrelevant fields }); Post.add({ title: { type: String, required: true }, en:

我正在扩展keystone.js以支持模型中的多种语言

原始模型如下所示:

Post.add({
    title: { type: String, required: true },
    publishedDate: { type: Types.Date, index: true },
    //... more irrelevant fields
});
Post.add({
    title: { type: String, required: true },
    en: {
        title: { type: String },
        publishedDate: { type: Types.Date, index: true },
        //... more irrelevant fields
    },
    es: {
        title: { type: String },
        publishedDate: { type: Types.Date, index: true },
        //... more irrelevant fields
    },
    //... more languages following the same pattern
});
我的扩展模型如下所示:

Post.add({
    title: { type: String, required: true },
    publishedDate: { type: Types.Date, index: true },
    //... more irrelevant fields
});
Post.add({
    title: { type: String, required: true },
    en: {
        title: { type: String },
        publishedDate: { type: Types.Date, index: true },
        //... more irrelevant fields
    },
    es: {
        title: { type: String },
        publishedDate: { type: Types.Date, index: true },
        //... more irrelevant fields
    },
    //... more languages following the same pattern
});
我在视图模板中使用嵌套的publishedDate属性时遇到问题

与原始模型一起使用的原始视图代码:

{% if post.publishedDate %}
    <br>on {{ post._.publishedDate.format('MMMM DD, YYYY') }}
{% endif %}

如果有人能解释一下为什么这样做(或者更好的方法),我将不胜感激。

@JRulle,我假设错误在以下几行:

<br>on {{ post[lang]._.publishedDate.format('MMMM DD, YYYY') }}

这是有效的。谢谢你的解释,因为这快把我逼疯了。
<br>on {{ post._[lang].publishedDate.format('MMMM DD, YYYY') }}