php - “日历.refetchEvents();” 不刷新事件
问题描述
我正在使用 fullcalendar v4 ( https://fullcalendar.io/ ),并且我试图在单击事件时删除事件。
当我点击一个事件时,我有这个代码来删除事件:
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
locale: 'pt',
plugins: [ 'interaction', 'dayGrid', 'timeGrid', 'list' ],
editable: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
},
// CUSTOM CODE DATABASE
events: load.php,
eventClick:function(clickedInfo)
{
if(confirm("Are you sure you want to delete this event?"))
{
var id = clickedInfo.event.id;
$.ajax({
url:"delete.php",
type:"POST",
data:{id:id},
success: function() {
alert('Deleted!');
calendar.refetchEvents();
}
})
}
},
});
calendar.render();
});
该事件正在数据库中被删除,因此该功能可以正常工作,但事件不会刷新,并且已删除的事件仍显示在日历中。只有当我完全刷新页面时它才会消失,这并不理想。
知道为什么吗?
解决方案
看起来日历对象从未被初始化过。
我会尝试按照文档中的说明更改您的事件侦听器:
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: [ 'dayGrid' ]
});
calendar.render();
});
参考。https://fullcalendar.io/docs/initialize-globals
我假设您使用的是脚本标签,但如果您使用的是构建系统(即 webpack),那么您可以试试这个:https ://fullcalendar.io/docs/initialize-es6
为了删除一个事件,我会试试这个:
eventClick:function(clickedInfo)
{
if(confirm("Are you sure you want to delete this event?"))
{
var id = clickedInfo.event.id;
$.ajax({
url:"delete.php",
type:"POST",
data:{id:id},
success: function() {
alert('Deleted!');
//calendar.refetchEvents(); // remove this
clickedInfo.event.remove(); // try this instead
}
})
}
},
推荐阅读
- r - 从数据框在 R 中创建包含 csv 文件的文件夹
- pandas - Python:在熊猫中操作时间数据框
- python - 使用线程外的数据更新 Tkinter 窗口标签变量
- windows - Windows 命名管道部分读取
- grafana - 使用默认用户名和密码在 Grafana 中登录问题
- ios - 访问 Assets 文件夹中的内部文件夹
- python-3.x - Tkinter 中的日记
- python-3.x - 运行 docker-compose 时出错 [pkg_resources.DistributionNotFound]
- swift - SiriShortcuts 不要求布尔参数
- ios - 从未使用有效格式解析的字节加载的 Swift DateFormatter 字符串