jQuery inArray() 禁用 Whole Calendar 中的 select 选项的日子



我正在尝试禁用FullCalendar中的特定日期。我的数据库中有一系列日期,可以阻止或取消阻止日期。

当我使用如下所示的inArray()时,它会阻止日历中的所有日期。不是jQuery大师,所以我需要一些帮助。

这就是我目前所拥有的;

select: function(start, end, jsEvent, view) {
    var disabledDates = ['2017-03-17', '2017-03-23'];
    if($.inArray(disabledDates) !== -1) {
        swal({
          title: "Date is blocked",
          text: "Sorry, the maximum Daily Bookings have been reached. Please select another date.",
          type: "warning"
        });
        $('#calendar').fullCalendar('unselect');
        return false;
    } else {
        $('#ModalAdd .start').val(moment(start).format('YYYY-MM-DD HH:mm:ss'));
        $('#ModalAdd .end').val(moment(end).format('YYYY-MM-DD HH:mm:ss'));
        $('#ModalAdd').modal('show');
        $('#calendar').fullCalendar('unselect');
        return true;
    };
}

任何建议都将被大大接受。

编辑

我已经编辑了上面的问题,但仍然无法让它工作,它应该只返回truefalse.

我使用 select: function 的原因是我只是希望模型不显示数组中是否有日期。

为什么这行不通?

以防万一有人需要这个解决方案,我终于让它工作了。

select: function(start, end, jsEvent, view) {
    var disabledDates = ['2017-03-17', '2017-03-23'];
    var selectedDate = moment(start).format('YYYY-MM-DD');
    if($.inArray(selectedDate, disabledDates) !== -1) {
        swal({
          title: "Date is blocked",
          text: "Sorry, the maximum Daily Bookings have been reached. Please select another date.",
          type: "warning"
        });
        $('#calendar').fullCalendar('unselect');
        return false;
    } else {
        $('#ModalAdd .start').val(moment(start).format('YYYY-MM-DD HH:mm:ss'));
        $('#ModalAdd .end').val(moment(end).format('YYYY-MM-DD HH:mm:ss'));
        $('#ModalAdd').modal('show');
        $('#calendar').fullCalendar('unselect');
        return true;
    };
}

最新更新