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

im feeding the calendar with the following function:$('#calendar').fullCalendar( {header: {le

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745138407a4613313.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信