如何在全日历中查看基于月份的数据

How to see data based on month in fullcalendar

我想在页面顶部添加一个带有月份的按钮。它在第一次点击时有效,但当我点击其他月份时,日历不再呈现。有什么想法吗?

请参阅此 fiddle 以获取代码:

https://jsfiddle.net/jetdk0ay/6/

事件代码

$(document).on('click', '.month', function(){
    $('#calendar').empty();
    // Render the calendar
});

与其尝试 re-render 日历,不如使用 'gotodate' 函数。看这里:https://jsfiddle.net/cz2s1uon/

主要是:

var calendar;
$(document).on('click', '.month', function(){
  
  var newDate = new Date();
  var month = $(this).attr('value');
  var fixedMonth = month - 1;
  newDate.setMonth(fixedMonth);
  
  if (calendar) {
    calendar.fullCalendar('gotoDate', newDate)
    return
  }

  calendar = $('#calendar').fullCalendar({
    defaultDate: newDate,
    events: []
  })
})

这是关于此功能的文档: https://fullcalendar.io/docs/v3/gotoDate