Php &引用;calendar.refetchEvents()&引用;不刷新事件
我使用的是fullcalendar v4(),我试图在单击事件时删除事件 当我单击某个事件时,我有以下代码来删除该事件:Php &引用;calendar.refetchEvents()&引用;不刷新事件,php,ajax,fullcalendar,fullcalendar-4,Php,Ajax,Fullcalendar,Fullcalendar 4,我使用的是fullcalendar v4(),我试图在单击事件时删除事件 当我单击某个事件时,我有以下代码来删除该事件: document.addEventListener('DOMContentLoaded', function() { var calendarEl = document.getElementById('calendar'); var calendar = new FullCalendar.Calendar(calendarEl, {
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();
});
参考文献
我假设您使用的是脚本标记,但如果您使用的是构建系统(即webpack),则可以尝试以下方法:
要删除事件,我只需尝试以下操作:
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
}
})
}
},
参考有错误吗?
calendar
是否在此范围内定义?我在控制台或页面上没有发现错误。我认为calendar是在此范围内定义的,因为它是一个全局变量。我刚刚更新了上面的代码。谢谢,谢谢。我试过了,但没有改变。删除后仍无法刷新事件。:-(请参阅上述问题中编辑的代码。是否有任何关于我可能缺少的内容的线索?我认为您根本不需要调用refetch函数。只需删除事件就会导致日历重新呈现。至少,在以前的版本中它是这样工作的。请继续查看我的编辑,试一试,并让我知道它是如何工作的。是的!!!!“clickedInfo.event.remove();”的效果非常好!:-)谢谢!