Fullcalendar eventDrop回调函数从全天事件到时间限制事件失败

时间:2015-08-10 19:52:20

标签: javascript fullcalendar

我有一个eventDrop回调函数,当从限时事件发送到限时事件时起作用,但从全天事件发送到限时事件时不起作用。任何人都可以告诉我我做错了什么或这是一个报告错误。我对fullcalendar没有足够的经验来确定它是哪一个。

请参阅下面的JS Bin链接,了解javascript和问题示例。

http://jsbin.com/taxopo/edit?js,output

$(function() { 
    $('#calendar').fullCalendar({
        header: {
          left: 'prev,next today',
          center: 'title',
          right: 'month,agendaWeek,agendaDay'
        },
        editable: true,
        eventLimit: true, // allow "more" link when too many events
        eventDrop: function(event, delta, revertFunc, jsEvent, ui, view) {event_drop(event, delta, revertFunc);},
        events: [{
            id: 'SCH1014',
            title: 'Mcm Plastics, Inc.',
            start: '2016-12-15',
            end: '2016-12-16',
            allDay: true,
            className: 'qtip-tip',
            color: '#76819D',
            description: 'Proposed Service Pending Email Request'
        },/*...*/]
    });
});

function event_drop(event, delta, revertFunc) {
    var start = jQuery.fullCalendar.moment(event.start.format('MM-DD-YYYY'));
    var end = jQuery.fullCalendar.moment(event.end.format('MM-DD-YYYY'));
    var myStartDate = start.format('MM-DD-YYYY');
    var myEndDate = end.format('MM-DD-YYYY');
    var id = event.id;
    var myEvent = [];

    if (start.hasTime()) {
        var myStartTime = start.format('hh:mm:ss A');
        var myEndTime = end.format('hh:mm:ss A');
        myEvent.push(id, myStartDate, myEndDate, myStartTime, myEndTime);
    } else {
        myEvent.push(id, myStartDate, myEndDate);
    }

    var data = '__myEvent='+myEvent;
    alert(data);
}

1 个答案:

答案 0 :(得分:2)

event.end并不总是设置,需要在尝试使用之前进行检查

以下内容应该有效:

function event_drop(event, delta, revertFunc) {
    var noEnd = false; 
    if(event.end == null){ 
        noEnd = true;
    }

    var start = jQuery.fullCalendar.moment(event.start.format('MM-DD-YYYY'));
    var end = noEnd || jQuery.fullCalendar.moment(event.end.format('MM-DD-YYYY'));


    var myStartDate = start.format('MM-DD-YYYY');
    var myEndDate = noEnd || end.format('MM-DD-YYYY');
    var id = event.id;
    var myEvent = [];

    if (start.hasTime()) {
        var myStartTime = start.format('hh:mm:ss A');
        var myEndTime = noEnd || end.format('hh:mm:ss A');
        myEvent.push(id, myStartDate, myEndDate, myStartTime, myEndTime);
    } else {
        myEvent.push(id, myStartDate, myEndDate);
    }

    var data = '__myEvent='+myEvent; // I have no idea what this is achieving
    alert(data);
}