我正在使用FullCalendar V4的回调函数。drop
. 我试图将服务器生成的myID传递给Calendar event.id,但我不知道该怎么做。以下是简单的代码
var calendar = new Calendar(calendarEl, {
drop: function( dropInfo ) {
$.getJSON( url, myParams, function( data ) {
// try to set data.myID to FullCalendar event id
calendarEvent = { id : data.myID };
});
},
eventClick: function( eventClickInfo ) {
var msg = "Are you sure to delete[" + event.title + "]?";
if ( confirm(msg) ) {
// It fails, because I can't get event.id
var params = { method: "deleteEvent", id: event.id };
$.get(url, params, function( data ){
eventClickInfo.event.remove();
});
}
}
});
我曾试图把calendar.refetchEvents();
进入 drop: $.getJSON(function(){})
响应块,但FullCalendar在UI中制造了2个事件。一个有balnk属性,另一个有right属性。如果我可以消除冗余,这将是一个很好的解决方案。
谢谢ADyson的建议。最后,我使用了回调函数 eventReceive
解决了这个问题。以下是我的简单代码
var calendar = new Calendar(calendarEl, {
eventReceive: function( info ) {
var $draggedEl = $( info.draggedEl );
var params = { method: "insert" };
$.ajaxSetup({ cache: false, async: false});
$.getJSON( myURL, params, function( data ){ // insert information into DB
info.event.setProp( "id", data.id );
});
},
eventClick: function( info ) {
var event = info.event;
var msg = "Are you sure to delete[" + event.title + "]?";
if ( confirm(msg) ) {
var params = { method: "deleteEvent", id: event._def.id };
$.get( myURL, params, function( data ){
event.remove();
});
}
},
});