我正在使用 {{#each}} 遍历 Meteor 中的集合,我想知道我是否在最后一个元素中,就像我在 AngularJS 中使用 $last 时可以做的那样。
例如,它可以用于构建人类可读的枚举,例如“我喜欢猫、狗和海豚”:
Template.myTemplate.helpers({
likedAnimals: function(){return ['dogs','cats','dolphins'];}
});
<template name='myTemplate'>
I like
{{#each likedAnimals}}
{{#if !$first && !$last}}, {{/if}}
{{#if $last}} and {{/if}}
{{this}}
{{/each}}
</template>
有没有办法在 Meteor 中检查这种情况?