使用 {{#each}} 迭代时如何不包含 Meteor 中的条目
When iterating with {{#each}} how to not include the entry in Meteor
我为其设计此应用程序的人要求她能够在接下来的 7 天内制作生日人的电子邮件列表。集合中的字段之一是 Bdate,格式为 'YYYY-MM-DD'。我决定用一种简单的算法制作一个 registerHelper 来确定生日是否符合要求:
Template.registerHelper('calculateBirthday', function(bdate) {
var birthDate = new Date(bdate);
var current = new Date();
var diff = current - birthDate; // Difference in milliseconds
var sevenDayDiff = Math.ceil(diff/31557600000) - (diff/31557600000);
if (sevenDayDiff <= 0.01995183087435)
return date;
else
return false;
});
该模板将有一个 table,其中列出了要为电子邮件列表获取的生日:
<table class="bordered">
<thead>
<tr>
<th>Name</th>
<th>Birthday</th>
</tr>
</thead>
<tbody>
{{#each QueryBirthday}}
<tr>
<tr>{{FullName}}</tr>
<td>{{calculateBirthday Bdate}}</td>
</tr>
{{/each}}
</tbody>
</table>
这个问题是它打印了所有生日大多为空的名字。该算法工作正常,但如何告诉 Meteor 只包含列表中 'should' 的那些姓名和生日?
隐藏不需要的项目的最快方法是
<table class="bordered">
<thead>
<tr>
<th>Name</th>
<th>Birthday</th>
</tr>
</thead>
<tbody>
{{#each QueryBirthday}}
{{#if calculateBirthday Bdate}}
<tr>
<td>{{FullName}}</td>
<td>{{calculateBirthday Bdate}}</td>
</tr>
{{/if}}
{{/each}}
</tbody>
</table>
我不知道您的应用程序是如何工作的,但像其他对您的问题发表评论的人一样,我会过滤并仅将所需的结果从服务器发送到客户端。
我为其设计此应用程序的人要求她能够在接下来的 7 天内制作生日人的电子邮件列表。集合中的字段之一是 Bdate,格式为 'YYYY-MM-DD'。我决定用一种简单的算法制作一个 registerHelper 来确定生日是否符合要求:
Template.registerHelper('calculateBirthday', function(bdate) {
var birthDate = new Date(bdate);
var current = new Date();
var diff = current - birthDate; // Difference in milliseconds
var sevenDayDiff = Math.ceil(diff/31557600000) - (diff/31557600000);
if (sevenDayDiff <= 0.01995183087435)
return date;
else
return false;
});
该模板将有一个 table,其中列出了要为电子邮件列表获取的生日:
<table class="bordered">
<thead>
<tr>
<th>Name</th>
<th>Birthday</th>
</tr>
</thead>
<tbody>
{{#each QueryBirthday}}
<tr>
<tr>{{FullName}}</tr>
<td>{{calculateBirthday Bdate}}</td>
</tr>
{{/each}}
</tbody>
</table>
这个问题是它打印了所有生日大多为空的名字。该算法工作正常,但如何告诉 Meteor 只包含列表中 'should' 的那些姓名和生日?
隐藏不需要的项目的最快方法是
<table class="bordered">
<thead>
<tr>
<th>Name</th>
<th>Birthday</th>
</tr>
</thead>
<tbody>
{{#each QueryBirthday}}
{{#if calculateBirthday Bdate}}
<tr>
<td>{{FullName}}</td>
<td>{{calculateBirthday Bdate}}</td>
</tr>
{{/if}}
{{/each}}
</tbody>
</table>
我不知道您的应用程序是如何工作的,但像其他对您的问题发表评论的人一样,我会过滤并仅将所需的结果从服务器发送到客户端。