【问题标题】:FullCalendar v4.2.0 destroy() not workingFullCalendar v4.2.0 destroy() 不工作
【发布时间】:2019-11-25 06:47:42
【问题描述】:

https://fullcalendar.io/docs/destroy

完整日历代码:

     document.addEventListener('DOMContentLoaded', function () {           
        var calendarEl = document.getElementById('calendar');
        var calendar = new FullCalendar.Calendar(calendarEl, {
            plugins: ['interaction', 'dayGrid', 'timeGrid'],                
            defaultDate: new Date(),
            navLinks: true,
            selectable: true,
            selectMirror: true,
            draggable: true,                
            editable: true,
            eventLimit: true, 
            events: [
                <?= $contents ?>
            ],                
        });

        calendar.render();
    });

FullCalendar v4.2 销毁不起作用 我尝试了以下,

 1. var calendarEl = document.getElementById('calendar');
    calendarE1.destroy();

 2. $("#calendar).destroy();

 3. calendarEl = document.getElementById('calendar');
    var calendar = new FullCalendar.Calendar(calendarEl, {
      plugins: ['interaction', 'dayGrid', 'timeGrid'],
    });
    calendar.destroy();

我尝试了这些东西,但没有任何帮助! 注意:我正在尝试销毁 ajax 成功的日历。
我的目标是我需要销毁旧事件并通过新事件重新初始化。

【问题讨论】:

  • 仅供参考,在您的示例 #1 中:calendarElcalendarE1 不同
  • “我的目标是我需要销毁旧事件并通过新事件重新初始化” ...在这种情况下,您不需要需要销毁整个日历。您可以自己添加和删除事件。

标签: javascript php html fullcalendar fullcalendar-4


【解决方案1】:

基本上,您可以从 DOMContentLoaded 中初始化主日历对象,并在该页面中将其用作全局对象,如下面的代码:

     var calendar;

     document.addEventListener('DOMContentLoaded', function () {           
     var calendarEl = document.getElementById('calendar');
     calendar = new FullCalendar.Calendar(calendarEl, {
            plugins: ['interaction', 'dayGrid', 'timeGrid'],                
            defaultDate: new Date(),
            navLinks: true,
            selectable: true,
            selectMirror: true,
            draggable: true,                
            editable: true,
            eventLimit: true, 
            events: [
                <?= $contents ?>
            ],                
        });

        calendar.render();
    });

现在在任何其他函数中,您可以调用它来销毁,如下所示:

if (calendar) {
   calendar.destroy();
}

另一种选择是使用此链接中所述的“refetchEvents”: how to refresh fullcalendar v4 after change events object using ajax

这个链接也可以帮助你: Destroy fullcalendar on bootstrap tabs click before new calendar is initialized

【讨论】:

  • 它工作正常,我按照第一种方法。非常感谢。
猜你喜欢
  • 1970-01-01
  • 2017-11-23
  • 2017-06-30
  • 1970-01-01
  • 2015-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多