所有星期天的jQuery FullCalendar活动

问题描述 投票:2回答:3

我需要在我的日历上为所有星期日添加一个活动。 FullCalendar中有没有可用的选项?

day = 'Sunday'; <------ I need to pass this day to create event

var date = new Date();
var event = {id: result.id, title: from_time + '-' + to_time, start: new Date(date), allDay: false};
                  }
$('#calendar').fullCalendar('renderEvent', event, true);
javascript jquery fullcalendar
3个回答
2
投票

您可以使用dow事件属性非常简单地完成此操作。它没有很好地记录,但它在backgroundEventsbusinessHours中提到过。它允许您设置事件始终发生的星期几。

所以像这样:

$("#calendar").fullCalendar({
    events:[{
        title:"Monday",
        dow:[1] //monday
        //start/endtime works too
    },{
        title:"background",
        dow:[2,3], //tuesday and wednesday
        rendering: 'background'
    }],
});

JSFiddle

如果你需要更复杂的东西,比如只在某个日期范围内重复活动,请看看我的答案:https://stackoverflow.com/a/29393128/728393


0
投票

请查找一些事件重复的参考代码。

 $('#calendar').fullCalendar( 'addEventSource',        
        function(start, end, callback) {
            // When requested, dynamically generate virtual
            // events for every sunday
            var events = [];

            for (loop = start.getTime();
                 loop <= end.getTime();
                 loop = loop + (24 * 60 * 60 * 1000)) {

                var test_date = new Date(loop);

                if (test_date.is().sunday()) {
                    // we're in Sunday, create the event
                    events.push({
                        title: 'I Love Sundays - Janty',
                        start: test_date
                    });
                }

            } // for loop

            // return events generated
            callback( events );
        }
    );

Repeat event every monday


-2
投票
events: [
              {
                  title:"Monday",
                  dow:[1] //monday
                  //start/endtime works too
              },{
                  title:"background",
                  *daysOfWeek*: [2, 3], //tuesday and wednesday
                  rendering: 'background'
              }]

© www.soinside.com 2019 - 2024. All rights reserved.