每个车把之间的注入div元素



我想在 #each

的第四个元素之后放置一个div
<script type="text/template" id="template">
{{#each names}}
  {{name}}
{{/each}}
</script>

如果没有4个元素,则最后。我该如何实现?

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;
      }
   }
)

最新更新