1

以下のコードを使用して、jQueryFullCalendarを初期化します。

ただし、すべての月にイベントがあるわけではありません。カレンダーの最初の月のビューを、イベントのある最初の月にします。

例として。現在は6月ですが、カレンダーには8月までイベントがないため、カレンダーの初期表示を6月ではなく8月にデフォルト設定したいと思います。

同様に、6月にイベントがある場合は、デフォルトで6月にします。

$('#fullCalendar').fullCalendar({
            selectable: true,
            selectHelper: true,
            header: {
                left: 'prev',
                center: 'title',
                right: 'next'
            },
            events: function(start, end, callback) {

                $.getJSON(jSONCalendarURL, {
                            token:jSONAPItoken,
                            productID: $('#fullCalendar').attr("data-id"),
                            startDate: $.fullCalendar.formatDate(start, 'yyyy-MM-dd'),
                            endDate: $.fullCalendar.formatDate(end, 'yyyy-MM-dd')
                        }, function(data){
                        var calevents = [];
                        $.each(data.response, function(index,item){
                            calDate = index;
                            child = item.Variations;
                            if (child.length > 0 ){
                                if (!$.isEmptyObject(child)){
                                    calPrice = child[0].Price;
                                    calID = child[0].ID;
                                    calAvailable = child[0].Available;
                                    calevents.push({
                                        'id': calID,
                                        'title': buildEventTitle(calAvailable,calDate.substring(calDate.length,calDate.length-2),child[0].Price, calID, child[0].RRP),
                                        'start': $.fullCalendar.parseDate(calDate),
                                        'end': $.fullCalendar.parseDate(calDate),
                                        'allDay': true
                                    });

                                }
                            }
                        });
                        callback(calevents);
                        highlightExisting();

                    }
                );
            },

            eventRender: function (event, element, view) {
                if (event.start.getMonth() != view.start.getMonth())
                    return false;
            },
            weekMode:'liquid'
        });

私がやろうとしていることは達成可能ですか?

4

1 に答える 1

6

間違いなく達成可能です!まず、イベント配列を並べ替えて、次に登録されているイベントオブジェクトを見つけることから始める必要があります。次に、.fullCalendar('gotoDate')メソッドを使用して、その日付にジャンプできます。

このようなもの:

function custom_sort(a, b) {
    return new Date(a.start).getTime() - new Date(b.start).getTime();
}

events_array.sort(custom_sort);

$('#calendar').fullCalendar('gotoDate', events_array[0].start);

動作する静的な例については、このFIDDLEを参照してください。

お役に立てれば!

于 2012-06-26T04:26:02.290 に答える