我想在DOM中构建的东西:
<table>
<tr> Today </tr>
<tr>
//data from Mongo
</tr>
...
<tr> Yesterday </tr>
....
//data from Mongo
..etc
</table>代码:
<table>
{{#each posts}}
{{> postJobs}}
{{/each}}
</table>
<template name="postJobs">
<tr>
... // data from Mongo
</tr>
</template>我认为有必要将蒙古文件的日期与今天的日期或类似的日期进行比较。
知道怎么建这个吗?
发布于 2015-07-16 20:29:39
我想您是在请求如何从按日期分组的集合中获取文档。
所以在上面看到今天的聊天,下一个街区昨天,下一个街区之前的聊天
只需调用3次相同的模板
<template name="main">
<h1>Today</h1>
{{> list_posts posts=today}}
<h1>Yesterday</h1>
{{> list_posts posts=yesterday}}
<h1>Previous</h1>
{{> list_posts posts=previous}}
</template>
<template name="list_posts">
<table>
{{#each posts}}
<tr>
<td>{{col1}}</td>
<td>{{colX}}</td>
</tr>
{{/each}}
</table>
</template>然后你需要这个帮手
Template.main.helpers({
today: function() {
return Posts.find() // col.date >= today
},
yesterday: function() {
return Posts.find() // col.date < today and >= yesterday
},
previous: function() {
return Posts.find() // col.date < yesterday
}
});祝你好运汤姆
发布于 2015-07-16 19:57:20
我不明白你到底想要实现什么。与今天的日期相比,在帮助器(您可以在{{#if compareDate}}语句中使用)中,日期如下所示:
compareDate: function(){
var today= new Date(new Date().getTime());
return this.date < today// it will get you true is the date field of your mongo document is older than today
}额外的信息,如果你昨天需要:
var yesterday = new Date(new Date().getTime() - (24 * 60 * 60 * 1000));https://stackoverflow.com/questions/31463213
复制相似问题