Meteor + Blaze - 如何仅在循环的最后一个元素中使用条件?

Meteor + Blaze - How can use a condition only in the last element of my loop?

这是我的:

Template.publicnewsjson.helpers({ 

news:function(){      

   return news.find({}, { sort: {date:-1} } );

   },

   newscount:function(){

    return news.find().count();
   }
});


  <template name="publicnewsjson">
   <pre>
     {{#each news}}
        {
              Title:{{title}}
              Date:{{friendlydate this.date}}
              Abstract:{{abstract}}
              HeadlineImagePath:{{headlineimagepath}}
              URL:{{url}}
              Source:{{source}}
        }, <------- This is the comma that I want to remove in the last repetition
     {{/each}}
   </pre>
  </template>

如何在最后一次重复中获取逗号? 我在尝试类似的东西?:

{{#if newscount @index}} 但它不起作用。

您可以创建一个辅助函数,我们称之为 last,它接受 @index 作为参数并使用 {{#unless last @index}},{{/unless}}

感谢您的帮助,我能够解决我的问题。 那是我的新代码:

Template.publicnewsjson.helpers({


   news:function(){  

   TAPi18n.subscribe('publicnewslistall', null);  

   return news.find({}, { sort: {date:-1} } );
},

islast:function(position){

 TAPi18n.subscribe('publicnewslistall', null);
 var size = news.find().count();

    if( size === position+1){
      console.log("ultimo");
      return true;
    }
    return false;
   }
});

<template name="publicnewsjson">  

<pre>[{{#each news}}{{#if islast @index}}{
                                      "Title":"{{title}}",
                                      "Date":"{{friendlydate this.date}}",
                                      "Abstract":"{{abstract}}",
                                      "HeadlineImagePath":"{{headlineimagepath}}",
                                      "URL":"{{url}}",
                                      "Source":"{{source}}"
                                }{{else}}

                                {
                                      "Title":"{{title}}",
                                      "Date":"{{friendlydate this.date}}",
                                      "Abstract":"{{abstract}}",
                                      "HeadlineImagePath":"{{headlineimagepath}}",
                                      "URL":"{{url}}",
                                      "Source":"{{source}}"
                                },{{/if}}{{/each}}]</pre>         
</template>