문제

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.

도움이 되었습니까?

해결책

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/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top