数据之events(函数)

优质
小牛编辑
123浏览
2023-12-01

自定义函数返回 Event Objects

function( start, end, callback ) { }

FullCalendar 会在需要数据的时候调用这个自定义函数,例如当用户切换视图的时候。

此函数会传入 start 和 end 参数(Date对象)来表示时间范围。另外还有 callback 函数,当自定义函数生成日程之后必须调用,callback的入参是 Event Objects 数组。

$('#calendar').fullCalendar({
    events: function(start, end, callback) {
        $.ajax({
            url: 'myxmlfeed.php',
            dataType: 'xml',
            data: {
                // our hypothetical feed requires UNIX timestamps
                start: Math.round(start.getTime() / 1000),
                end: Math.round(end.getTime() / 1000)
            },
            success: function(doc) {
                var events = [];
                $(doc).find('event').each(function() {
                    events.push({
                        title: $(this).attr('title'),
                        start: $(this).attr('start') // will be parsed
                    });
                });
                callback(events);
            }
        });
    }
});

使用 eventSources:

$('#calendar').fullCalendar({

    eventSources: [

        // your event source
        {
            events: function(start, end, callback) {
                // ...
            },
            color: 'yellow',   // an option!
            textColor: 'black' // an option!
        }

        // any other sources...

    ]

});

官方英文文档:http://arshaw.com/fullcalendar/docs/event_data/events_function/