JS - FullCalendar:当月份改变时收听
JS - FullCalendar : Listen when the month changes
我在使用 FullCalendar v5 时遇到了一些小问题,我使用 dayGridMonth
视图对其进行了配置,我希望 在用户更改当前月份时收听 ...
例如,如果他看到二月并单击 next
,他会看到三月,所以我期望像 onChange
或 onMonthChange
这样的处理程序,但我没有在文档中找不到任何东西来做这样的事情......
我想出了如何通过制作自己的上一个/下一个按钮并在点击时触发我的自定义处理程序来解决这个问题......但我想知道是否有一种普通的方法可以做到这一点?
感谢您的回答。
正如@Devsi Odedra 所提到的,答案是 datesSet
文档:https://fullcalendar.io/docs/datesSet
这是我的实际代码,如果它可以帮助别人:
new Calendar(document.getElementById("calendar"), {
plugins: [ dayGridPlugin, interactionPlugin ],
datesSet: event => {
// As the calendar starts from prev month and end in next month I take the day between the range
var midDate = new Date((event.start.getTime() + event.end.getTime()) / 2).getMonth()
var month = `0${ midDate.getMonth() + 1 }`.splice(0, -1)
doSomethingOnThisMonth(month, midDate.getFullYear())
}
});
function doSomethingOnThisMonth(month, year) {
fetch(`myApi.com/something?month=${ month }&year=${ year }`)
.then((result) => {
// Do something
})
}
我在使用 FullCalendar v5 时遇到了一些小问题,我使用 dayGridMonth
视图对其进行了配置,我希望 在用户更改当前月份时收听 ...
例如,如果他看到二月并单击 next
,他会看到三月,所以我期望像 onChange
或 onMonthChange
这样的处理程序,但我没有在文档中找不到任何东西来做这样的事情......
我想出了如何通过制作自己的上一个/下一个按钮并在点击时触发我的自定义处理程序来解决这个问题......但我想知道是否有一种普通的方法可以做到这一点?
感谢您的回答。
正如@Devsi Odedra 所提到的,答案是 datesSet
文档:https://fullcalendar.io/docs/datesSet
这是我的实际代码,如果它可以帮助别人:
new Calendar(document.getElementById("calendar"), {
plugins: [ dayGridPlugin, interactionPlugin ],
datesSet: event => {
// As the calendar starts from prev month and end in next month I take the day between the range
var midDate = new Date((event.start.getTime() + event.end.getTime()) / 2).getMonth()
var month = `0${ midDate.getMonth() + 1 }`.splice(0, -1)
doSomethingOnThisMonth(month, midDate.getFullYear())
}
});
function doSomethingOnThisMonth(month, year) {
fetch(`myApi.com/something?month=${ month }&year=${ year }`)
.then((result) => {
// Do something
})
}