FullCalendar 日历开始日期

FullCalendar calendar start date

我试图在我的日历上禁用前几天,因此 select 事件不会在那些日期执行。

我试过了

  defaultDate: '2015-03-25',
  minDate: '2015-03-25',

  eventConstraint: {
    start: '2015-03-25'
  },

有人知道我该怎么做吗?

谢谢

更新 -- 像这样吗?

  viewRender: function(view){
          if (view.start < minDate){
              $('#calendar').fullCalendar('gotoDate', minDate);
          }
      },

禁止查看过去

假设您在 viewRender 更新中的代码是所需的行为,它应该是:

viewRender: function(view){
      if (view.start.isBefore(moment())){  //if view start is before now
          $('#calendar').fullCalendar('gotoDate', moment); //go to now
      }
  },

Fullcalendar 使用 momentjs 日期库,因此您不能使用 < 进行比较。

JSFiddle demo

但这有点奇怪。您确定不想让人们看到 过去吗?一个月过半的时候呢?

将事件限制到现在

让我们添加一些调整以使其更有用:

  • 两个 background events,都涵盖相同的日期(从过去到现在 date/time)。我们需要一个作为全天活动,一个作为定时活动,因为:

    Background events that are timed will only be rendered on the time slots in agenda view. Background events that are all-day will only be rendered in month view or the all-day slots of agenda view.

  • selectOverlap and eventOverlap callbacks. These provide an easy way to stop the user from creating or moving events to the past.

events: [{ // All-day past
    id: 'past',
    start: '1900-01-01',
    end: moment(),
    rendering: 'background',
    allDay: true
}, { // Timed past
    id: 'past',
    start: '1900-01-01',
    end: moment(),
    rendering: 'background',
}, /*other event sources...*/ ],

// Disable selection on top of the "past" event
selectOverlap: function (event) {
    return event.id !== 'past';
},
// Disable dragging on top of the "past" event
eventOverlap: function (stillEvent, movingEvent) {
    return stillEvent.id !== 'past';
},

JSFiddle Demo