如何将fullcalendar事件限制为仅一天?

时间:2015-03-20 13:29:04

标签: javascript jquery fullcalendar

是否可以限制FullCalendar,因此在创建事件拖动时,该事件不会在其他日期发生?

我的意思是:如果我在3月20日09:00开始选择,我希望用户不能选择在3月21日13:00结束的活动。

2 个答案:

答案 0 :(得分:4)

您可以在日历设置中添加eventConstraint

eventConstraint:{
          start: '00:00', // a start time (start of the day in this example)
          end: '24:00', // an end time (end of the day in this example)
        }, 

您可以复制in this plunker

如果你想在拖动过程中限制它,我想你只能用eventDrop callback来做。如果moment.startOf('day)不同,您可以使用revertFunc将拖放动作恢复到之前的状态。

类似的东西:

$('#calendar').fullCalendar({
    events: [
        // events here
    ],
    editable: true,
    eventDrop: function(event, delta, revertFunc) {

        if (!event.start.startOf('day').isSame(event.end.startOf('day'))) {
             revertFunc();
        }
    }
});

答案 1 :(得分:-1)

$('#calendar').fullCalendar({
events: [
    {
        title  : 'event1',
        start  : '2010-01-01'
    },
    {
        title  : 'event2',
        start  : '2010-01-09T09:30:00',
        end    : '2010-01-09T15:30:00',
    },
    {
        title  : 'event3',
        start  : '2010-01-09T12:30:00',
        allDay : false // will make the time show
    }
]

});