fullCalendar jQuery,每个星期一重复? [英] fullCalendar jQuery, repeat every monday?

查看:181
本文介绍了fullCalendar jQuery,每个星期一重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常这是日历中的事件:

  {

标题:'Test',

开始:'2012-06-08',

结束:'2012-06-08',

url:'test / test '

},

正常工作。虽然我怎样才能让每个星期一在日历上显示1个事件?或者每个星期二等都取决于您进入的周日/号码?如果存在的话,那么参数是什么?

如果它不存在,我可以以某种方式修改并添加用于实现此功能的功能吗?所以你可以输入一个像repeatEveryWeekDay:2(这是星期一)的参数,然后在所有未来的星期一,数据将显示在那里。



我尝试寻找http://arshaw.com/fullcalendar/docs/event_data/Event_Object/ ,但无法找到任何内容。

解决方案

fullCalendar 允许您传递一个事件数组而不是传递一个函数例如,从服务器下载事件,或动态生成这些事件。

文档中的大多数示例都使用HTTP请求来获取事件数据。但回调函数仍然具有足够的灵活性,可以按照您的需要进行工作。



查看我刚刚为您写的以下示例:

  $(document).ready(function(){

var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();

$('#calendar') .fullCalendar({
header:{
left:'prev,next today',
center:'title',
right:'month,agendaweek,agendaDay'
$,
editable:true,
events:[
//一些原始的fullCalendar示例
{
title:'All Day Event',
start :new Date(y,m,1)
},
{
title:'Long Event',
start:new Date(y,m,d-5),
结束:新日期(y,m,d-2)
},
{
id:999,
title:'Repeating Event',
start:new Date(y,m,d-3,16,0),
allDay:false
}
]
});

//添加每个星期一和星期三事件:
$('#calendar')。fullCalendar('addEventSource',
function(start,end,callback){
//当请求时,为每个星期一和星期三动态生成虚拟
//事件。
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()。monday()){
//我们在Moday中创建事件
events.push({
标题:'我讨厌mondays - 加菲猫',
start:test_date
));
}

if(test_date.is()。wednesday()) {
//我们在星期三,crea周三活动
events.push({
title:'It''th the middle of week!',
start:test_date
});
}
} // for循环

//返回事件产生
callback(events);
}
);
});

上述函数自动为两个日期之间的每个星期一和星期三生成一个事件。日期显示在开始结束参数中。这些参数通过 fullCallendar 传递。上述函数生成的事件通过第三个参数中的 callback 函数返回到 fullCallendar



我使用 DateJS 来测试给定日期是否为星期一。



更新:如果要混合静态事件和/或[多个]可重复事件,可以使用 addEventSource


Normally this is a event in calendar:

            {

                title: 'Test',

                start: '2012-06-08',

                end: '2012-06-08',

                url: 'test/test'

            },

Works fine. Although how can i make 1 event that shows on every Monday in the calendar? Or every tuesday and so on depend on what weekday/number you enter? Whats the param if there exists one?

If it does not exists, can I somehow modify and add the feature for making this happen? So you can enter a param like repeatEveryWeekDay: 2 (which is monday), then on all future mondays the data will show there.

I tried looking in http://arshaw.com/fullcalendar/docs/event_data/Event_Object/ but can't find anything.

解决方案

fullCalendar permits that instead of passing an array of events, you can pass a function which, for example, downloads the events from a server, or dynamically generates those events.

Most examples in the documentation use HTTP requests to get events data. But the callback function is still flexible enough to make it work the way you want.

Look at the following example I've just written for you:

$(document).ready(function() {

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        editable: true,
        events: [
            // some original fullCalendar examples
            {
                title: 'All Day Event',
                start: new Date(y, m, 1)
            },
            {
                title: 'Long Event',
                start: new Date(y, m, d-5),
                end: new Date(y, m, d-2)
            },
            {
                id: 999,
                title: 'Repeating Event',
                start: new Date(y, m, d-3, 16, 0),
                allDay: false
            }
        ]
    });

    // adding a every monday and wednesday events:
    $('#calendar').fullCalendar( 'addEventSource',        
        function(start, end, callback) {
            // When requested, dynamically generate virtual
            // events for every monday and wednesday.
            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().monday()) {
                    // we're in Moday, create the event
                    events.push({
                        title: 'I hate mondays - Garfield',
                        start: test_date
                    });
                }

                if (test_date.is().wednesday()) {
                    // we're in Wednesday, create the Wednesday event
                    events.push({
                        title: 'It\'s the middle of the week!',
                        start: test_date
                    });
                }
            } // for loop

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

The above function automatically generates an event for every Monday and Wednesday between two dates. The dates are indicated in start and end params. Those params are passed by fullCallendar. Events generated by the above function are returned to fullCallendar through the callback function in third param.

I use DateJS to test if a given date is monday.

UPDATE: If you want to mix static events and/or [more than one] repeatable event, you can use addEventSource.

这篇关于fullCalendar jQuery,每个星期一重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆