簡體   English   中英

在 FullCalendar 5 中更改月份視圖時是否有回調?

[英]Is there a call back when month view was changed in FullCalendar 5?

我希望能夠獲得當前月份和年份 = 日歷標題。

日歷很簡單,只是每月查看。 我發現以前的版本中過去很少有回調,但在當前(V5.x)版本中我找不到任何回調。

我看到如何解決這個問題的唯一方法是為月份更改創建自定義按鈕。

document.getElementById('my-prev-button').addEventListener('click', function() {
  calendar.prev();
  // and here I can get the title
});

用戶更改一個月后,是否有任何本地方法如何獲取當前標題?

工作jsfiddle

在此處輸入圖像描述

作為一種解決方法 - 我仍然更喜歡原生解決方案 - 我使用了MutationObserver

var Calendar = FullCalendar.Calendar;
var calendarEl = document.getElementById('calendar');

calendar = new Calendar(calendarEl, {
  initialView: 'timeGridWeek',
  allDaySlot : false,
  slotMinTime : "06:00:00",
  slotMaxTime : "20:00:00",
  firstDay : 2,
  selectable: true,
  select: function(info) {
    console.log('selected ' + info.startStr + ' to ' + info.endStr);

  }
})
   
calendar.render()
   
var target = document.getElementsByClassName('fc-toolbar-title')[0]
var observer = new MutationObserver(function(mutations) {
  console.log(target.innerText);   
  console.log("comming from obeserver")
});
var config = { attributes: true, childList: true, characterData: true, subtree: true };
observer.observe(target, config);

工作jsFiddle 在這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM