FullCalendar 4中eventDragStop的jsEvent参数未定义问题求助
解决FullCalendar 4中eventDragStop的jsEvent undefined错误
嘿,我刚好碰到过类似的问题!你遇到的TypeError: jsEvent is undefined是因为FullCalendar 4对互动回调的参数格式做了重大调整——和v3及更早版本不一样啦!
问题根源
FullCalendar 4开始,像eventDragStop这类互动相关的回调函数,不再传递单独的event、jsEvent、view参数,而是把所有相关数据都封装到一个单一的info对象里。你现在的代码还是用的旧版本参数结构,所以直接去取jsEvent自然会找不到,导致undefined错误。
修复步骤
修改eventDragStop的参数结构
把原来的参数列表换成单个info对象,然后从里面解构出你需要的event、jsEvent和view:修正事件移除的调用方式
你代码里用的$('#calendar-holder').calendar('removeEvents', event._id);是jQuery风格的旧调用方式,FullCalendar 4已经改用实例方法了,直接用你创建的calendar变量调用removeEvents即可,同时注意事件id的属性是event.id而非event._id。
修改后的完整eventDragStop代码
eventDragStop: function(info) { const event = info.event; const jsEvent = info.jsEvent; if(isEventOverDiv(jsEvent.clientX, jsEvent.clientY)) { // 使用calendar实例的removeEvents方法 calendar.removeEvents(event.id); var el = $( "<div class='fc-event'>" ).appendTo( '#external-events-listing' ).text( event.title ); el.draggable({ zIndex: 999, revert: true, revertDuration: 0 }); el.data('event', { title: event.title, id : event.id, stick: true }); } }
额外提示
FullCalendar 4的所有回调函数几乎都改成了这种info对象参数的形式,如果你还有其他类似的回调(比如eventDrop、eventResize),也需要同步调整参数结构哦。
内容的提问来源于stack exchange,提问作者Woeler
相关产品推荐
相关产品推荐

