2017-07-05 1 views
1

Iループのための方法を実行します。Firebaseでオーバーヴュー - V-用経由でカレンダーの日を通じてすべてのV-ためのアイテム

<ul><li v-for="day in daysInMonth"></li></ul>

は、私が保存されたイベントがあります。各イベントには、日付のプロパティを持っています

eVeNtKeY 
    date: 12/7/17 

今、毎日がイベントを持っていませんが、私は日ごとにイベントカウントを取得する必要があります。その月のすべてのイベントをFirebaseコール経由でダウンロードし、Vue dataに配列thisMonthsEventとして保存しました。

data: { 
    thisMonthsEvents: [bunch of firebase data], 
    currentMonth: number 
} 

v-forのすべての反復のための方法を実行する方法はありますか?私の考えでは、私はこのような何かができる:

computed: { 
     eventsByDay() { 
      return this.thisMonthsEvents.filter(function (event) { 
      return event.date === this.currentMonth + '-' + Somehow get the day from loop + '-2017' 
}); 
     } 
     } 
+0

メソッド 'eventsByDay(day)'の引数として現在の日を追加し、そこに使用します。また、 'v-for'ループの中でそれを渡します:'

  • {{eventsByDay(day)}}
  • 'の日。 – wostex

    答えて

    1

    ではなく、計算されたプロパティのメソッドを使用してday変数に渡し、v-forループに直接メソッドを呼び出します。

    methods: { 
        getEventsByDay(day) { 
        return this.thisMonthsEvents.filter(function (event) { 
         return event.date === this.currentMonth + '-' + day + '-2017' 
        }); 
        } 
    } 
    

    <li v-for="day in daysInMonth"> 
        {{ getEventsByDay(day) }} 
    </li> 
    
    +0

    パーフェクト!追加しなければならなかったのは、カウントを得るのに '.length'だけでした。 – Auzy

    関連する問題