如何在模板中渲染余烬数据日期

pol*_*ick 2 ember.js

我正在尝试在我的车把模板中打印日期attr.但输出是空的.我该如何呈现它?

我的型号:

App.Post = DS.Model.extend({
    type: DS.attr('string'),
    title: DS.attr('string'),
    summary: DS.attr('string'),
    body: DS.attr('string'),
    date: DS.attr('date')
});


App.Post.FIXTURES = [
    {id:1, type:"news", title:"Some", summary:"Lorem ", date:new Date()}, 
    {id:2, type:"gallery", title:"Some", summary:"Lorem", date:new Date()}
];
Run Code Online (Sandbox Code Playgroud)

我的车把模板:

<script type="text/x-handlebars" data-template-name="posts">
    {{#each post in controller}}
        {{post.date}}: {{post.type}}- {{post.title}}
    {{/each}}
</script>
Run Code Online (Sandbox Code Playgroud)

msp*_*ars 6

你不能在Fixture本身使用新的Date(),你应该使用ISOstring或类似的东西.请记住,Date的转换会查找来自持久层(在您的情况下为Fixture)的字符串,然后将其转换为字符串中的Date对象.

因此,将您在夹具中的日期设置为"2013-02-07T16:44:57.000Z"或类似的东西,即"2013-02-07T16:44:57"也应该起作用.