Sim*_*eau 0 javascript fullcalendar fullcalendar-5
我在使用 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
})
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6060 次 |
| 最近记录: |