我想在#each
<script type="text/template" id="template">
{{#each names}}
{{name}}
{{/each}}
</script>
如果最后没有4个元素。我怎样才能做到这一点?
答案 0 :(得分:2)
HTML
{{#each names}}
{{name}}
{{#if fourth @index count}}
<div></div>
{{/if}}
{{/each}}
JS
Template.templateName.helpers(
{
count: function(){
//if you are using iron router to return names
return Router.current().data().names.find().count();
// or you could get length from a reactive variable or session
// or if you are returning names as a helper, then set the length there
},
fourth: function(i, count){
i = i+1;
return i%4===0 || count===i;
}
}
)