Question

Hello folks I am trying to utilize the fullcalendar to display some holidays I have acquired from a json object.

JSON looks as follows.

    var holidayObj = [
            {
                "holidayName" : "Boxing Day",
                "holidayStart" : "May, 26 Oct 2014 13:00:00 EST",
                "holidayEnd" : "May, 26 Oct 2014 13:00:00 EST"  
            }
            {
                "holidayName" : "Some other Day",
                "holidayStart" : "May, 23 Oct 2014 13:00:00 EST",
                "holidayEnd" : "May, 23 Oct 2014 13:00:00 EST"  
            }

        ];

My JS code to display the events on fullcalendar is as follows.

    $.each(holidayObj, function(i, item) {
        holidayNameText = item.holidayName;
        console.log(holidayNameText); //"Boxing Day"
        holidayStart = item.holidayStart; //May, 26 Oct 2014 13:00:00 EST
        holidayEnd = item.holidayEnd; //May, 26 Oct 2014 13:00:00 EST

        var eventObject = {
                title: holidayNameText,
                start: holidayStart,
                end : holidayEnd,
                allDay:true
            };   
        $('#calendar').fullCalendar('renderEvent', eventObject, true);
        console.log(eventObject.start);
    });

For some reason the events don't seem to be populating on the calendar. Can anyone help me identify what the cause might may be?

Thank you.

Was it helpful?

Solution

You are missing a comma to separate the array elements:

var holidayObj = [{
    "holidayName": "Boxing Day",
        "holidayStart": "May, 26 Oct 2014 13:00:00 EST",
        "holidayEnd": "May, 26 Oct 2014 13:00:00 EST"
}, {
    "holidayName": "Some other Day",
        "holidayStart": "May, 23 Oct 2014 13:00:00 EST",
        "holidayEnd": "May, 23 Oct 2014 13:00:00 EST"
}];

By fixing it, it works fine (see the events in October).

Demo: http://jsfiddle.net/IrvinDominin/EGbHt/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top