javascript - fullCalendar renderEvent 不粘连

标签 javascript jquery

我正在尝试将一个事件插入到我的 fullcalendar 中,并在刷新页面时让它在那里,但由于某种原因它消失了。

    <script>
$(document).ready(function() {

    // page is now ready, initialize the calendar...

    $('#calendar').fullCalendar({
    header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,basicWeek,basicDay'
        },
        selectable: true,
        selectHelper: true,
        select: function(start, end) {
            var title = prompt('Event Title:');
            var eventData;
            if (title) {
                eventData = {
                    title: title,
                    start: start,
                    end: end
                };

                $('#calendar').fullCalendar('renderEvent', eventData, true);

            }
            $('#calendar').fullCalendar('unselect');
        },
    })

});
</script>

我也尝试更改代码,使其看起来像这样

                    if (title)
                {
                    calendar.fullCalendar('renderEvent',
                        {
                            title: title,
                            start: start,
                            end: end,
                            allDay: allDay                          },
                        true 
                    );
                }
                calendar.fullCalendar('unselect');
            },

但我在页面上什么也没有,就像我错过了一些东西

最佳答案

当您刷新页面时,数据会消失,因为您没有在任何地方保存新事件,也没有任何函数来检索以前保存的事件。新事件仅存在于浏览器文档中。一旦您离开页面,文档的数据就会被丢弃。

您需要将数据保存在某个地方(客户端或服务器端),然后您需要在每次页面加载时检索保存的数据。传统上,程序员将数据存储在服务器端,通常存储在数据库中。 Client-side storage将数据存储在浏览器中,如果用户只需要访问自己的数据但有许多限制(例如,您的工作计算机和家庭计算机将保存不同的数据),则该数据非常有用。

关于javascript - fullCalendar renderEvent 不粘连,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27842083/

相关文章:

php - WordPress Jquery Cycle2 插件无法正常工作

php - 存储数据的最佳方式

javascript - Laravel 和 Surveyjs

javascript - JS 揭示模块模式 : Params that shouldn't be used by usercode

php - 如何使用 PHP、jQuery 和 AJAX 上传多个文件

javascript - 使用 javascript(jquery) 从外部 SVG 文件获取或设置 css 类值

javascript - 在搜索框中的关闭按钮上使用 jquery 事件

javascript - jquery 防止默认问题

javascript - 带有 templateResult 和 templateSelection 的 jquery select2 (4.0) ajax

javascript - 使用占位符和替换对象格式化 JavaScript 字符串?