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

javascript - Events are not appearing after being added - Stack Overflow

programmeradmin2浏览0评论

I'm trying to integrate FullCalendar with jQuery into my WordPress site using the Divi theme.

I have successfully:

Loaded FullCalendar via functions.php Ensured jQuery and Moment.js are enqueued correctly Logged the event data in the console after adding an event Issue: Despite everything looking correct in the console, the event does not appear on the calendar after being added. Additionally, I receive the following errors:

Deprecation Warning about date formatting: "Value provided is not in a recognized RFC2822 or ISO format". FullCalendar does not render the event even though it logs successfully in the console. No server storage (events are stored in a local array for now).

Here is my FullCalendar initialization script inside functions.php:

function initialize_fullcalendar() {
    ?>
    <script>
    jQuery(document).ready(function($) {
        if ($("#calendar").data("fullCalendar")) { 
            console.log("FullCalendar already initialized. Skipping re-initialization.");
            return;
        }

        console.log("FullCalendar is initializing...");

        var eventList = []; // Store events locally

        $("#calendar").fullCalendar({
            header: {
                left: "prev,next today",
                center: "title",
                right: "month,agendaWeek,agendaDay"
            },
            selectable: true,
            editable: true,
            eventLimit: true,
            events: function(start, end, timezone, callback) {
                console.log("Loading events...", eventList);
                callback(eventList);
            },

            select: function(start, end) {
                var eventTitle = prompt("Enter Event Title:");
                if (eventTitle) {
                    var eventData = {
                        id: eventList.length + 1,
                        title: eventTitle,
                        start: moment(start).toISOString(),
                        end: end ? moment(end).toISOString() : null
                    };

                    console.log("Adding Event:", eventData);

                    eventList.push(eventData);
                    $("#calendar").fullCalendar("renderEvent", eventData, true);
                }
                $("#calendar").fullCalendar("unselect");
            }
        });
    });
    </script>
    <?php
}
add_action('wp_footer', 'initialize_fullcalendar', 20);

Why are the events I add not displaying? Any help would be greatly appreciated

发布评论

评论列表(0)

  1. 暂无评论