これは私が持っているものです。Meteor + Blaze - ループの最後の要素でのみ条件を使用する方法はありますか?
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}}でも動作しません。あなたはヘルパー関数を作成することができます
新しいヘルパーを追加します。 islast:function(i){return news.find()。count()-1 === i;} – iiro
@alvespedroこの投稿は役に立ちましたか?https://stackoverflow.com/questions/21815713/in-meteor-is-スペースバーの配列インデックスへのアクセス方法 –