【问题标题】:possible bug with fullCalendar gotoDate and getDatefullCalendar gotoDate 和 getDate 可能存在的错误
【发布时间】:2012-06-15 02:22:56
【问题描述】:

我不希望人们试图在我的 fullCalendar 中创建过去的事件。因此,一旦他们选择了日期/时间,我会进行如下快速检查:

select: function(start, end, allDay) { 
        // need to check the day first. If the selected day/time < today, throw an alert
        // otherwise allow the booking of the conference.
            var now = calendar.fullCalendar('getDate');
            if (start < now )
            {
                alert('You cannot book a conference in the past!' +start +now);
                calendar.fullCalendar( 'unselect' );
            }
            else
            {
                             // other stuff here
                            }

这很好用。如果我点击早于现在的时间或日期,我会收到一条警报,说我不能这样做。完美吧?

我正在使用 jQuery DatePicker,我可以在一个小日历视图中单击一个日期,然后在我的 fullCalendar 中转到该日期,该日期默认为仅议程视图。效果很好:

$( "#datepicker" ).datepicker({
        changeMonth: true,
        changeYear: true,
        minDate: 0, 
        maxDate: "+1Y",
        onSelect: function(dateText) {
            // fullCalendar only accepts a date in a specific format so parse the date
            // from the jQuery DatePicker widget and use that result to move the calendar
            // to the correct day.
            var pd = $.fullCalendar.parseDate(dateText);
            $('#calendar').fullCalendar('gotoDate', pd);
        }

    });

这个例程让我在议程视图中处于正确的一周。然后我可以选择在该周工作的日期。但是,如果我尝试在使用 gotoDate 方法去的日期之前的日期创建事件,我也会收到关于过去创建事件的错误。似乎“gotoDate”方法实际上是在设置日期。我可以在该日期或之后创建活动,但不能在该日期之前创建。

如果我只使用 fullCalendar 的导航方法,它应该可以完美运行。但是因为 fullCalendar 没有“跳转到日期”选项或小部件,所以我使用 DatePicker 自己创建,我认为这样做是合乎逻辑的。

那么,这是一个错误吗?还是我做错了什么?

【问题讨论】:

  • 如何使用 var d = new Date(); 获取当前日期然后只需将所选日期转换为日期对象,然后将其与当前日期进行比较。
  • 这可能会更好,但这似乎仍然是一个错误恕我直言。会尝试你的建议。
  • 我不认为这是一个错误。 getDate 不返回 'today' - 它返回日历中当前选定的日期。对于月视图,它是在该月的第一天和最后一天之间选择的任何日期;对于周视图,它是该周中的任何一天。所以你的检查 (if(start
  • 是的,在我声明这是一个错误之前,我想与其他开发人员核实一下。你的解释是我澄清我的理解所需要的,它非常有道理。我更改为使用 Kyoka 建议的日期对象,但由于他没有将其说明为答案,因此我自己在这里回答了您的两个输入的问题。谢谢。

标签: jquery jquery-ui fullcalendar


【解决方案1】:

是的,感谢 Kyoka 和 Ganeshk 的 cmets 回答我自己的问题。碰巧的是,fullCalendar('getDate') 函数返回当前选择的日期,而不是“今天”。这只是我对文档的误解。那么解决方案是使用一个新的 Date 对象,在这种情况下它可以完美地工作:

select: function(start, end, allDay) { 
    // need to check the day first. If the selected day/time < today, throw an alert
    // otherwise allow the booking of the conference.
        var now = new Date();
        if (start < now )
        {
            alert('You cannot book a conference in the past!');
            calendar.fullCalendar( 'unselect' );
        }
        else
        {
                         // other stuff here
                        }

希望这对其他人也有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-10
    • 2019-04-18
    • 2013-10-11
    相关资源
    最近更新 更多