0

我正在使用 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 属性。如果我可以消除冗余,那将是一个很好的解决方案。

4

1 回答 1

1

感谢阿迪森的建议。最后,我用回调函数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();
            });
        }
    },
});
于 2020-06-11T01:42:07.100 回答