最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - fullCalendar custom events function throws not a function error - Stack Overflow

programmeradmin1浏览0评论

im feeding the calendar with the following function:

$('#calendar').fullCalendar( {
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay' },
        editable: true,
        eventLimit: true,
        events: function(callback) {
            $.ajax({
                url: '/appointments.json',
                dataType: 'json',
                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);
                }
            });

But i keep getting this error:

object is not a function //callback(events) line

On the js console of the browser. Any idea what the problem might be?

im feeding the calendar with the following function:

$('#calendar').fullCalendar( {
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay' },
        editable: true,
        eventLimit: true,
        events: function(callback) {
            $.ajax({
                url: '/appointments.json',
                dataType: 'json',
                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);
                }
            });

But i keep getting this error:

object is not a function //callback(events) line

On the js console of the browser. Any idea what the problem might be?

Share Improve this question edited Oct 14, 2014 at 13:16 ntonnelier asked Oct 14, 2014 at 13:09 ntonnelierntonnelier 1,5494 gold badges24 silver badges51 bronze badges 1
  • events: '/appointments.json' works just fine. The problem is in the function – ntonnelier Commented Oct 14, 2014 at 13:17
Add a ment  | 

1 Answer 1

Reset to default 4

Assuming you are using FullCalendar 2.*, as stated in the documentation, the signature for events is

function( start, end, timezone, callback ) { }

The parameter with the name callback is, in fact, start which is a momentjs object. To resolve your issue you must add the parameters to your function, so your code would be:

events: function( start, end, timezone, callback ) {

This will work as long as your events (passed to the callback) have the correct format and parameters defined in the documentation.

Edit:

If you want to set background color of each event according to a value on its json attributes, you should use eventRender. Check this jsfiddle where the background of each event is set when the event is rendering.

As is demonstrated in the jsfiddle, you can change the background, conditionally, based on a value provided by the json.

发布评论

评论列表(0)

  1. 暂无评论