fullcalendar today按钮需要双击触发事件

fullcalendar today button needs double-click to trigger the event

我在月、议程周和议程日(带资源)视图中使用全日历,我在议程日视图中的“今日”按钮遇到了一些问题。虽然 Prev 和 Next 按钮按预期工作,但我需要点击 Today 按钮两次才能触发点击事件,即使它只需要在其他视图中点击一次。

$('#calendar').fullCalendar({
    ...
    viewRender: function () {
        var $todayButton = $('.fc-today-button');
        $todayButton.removeClass('fc-state-disabled');
        $todayButton.prop('disabled', false);
    },
    ...
});

$(document).on('click', '.fc-prev-button, .fc-today-button, .fc-next-button', function () {
    console.log('CLICKED!');
});

更新:当我从全日历设置中删除这些行时,问题消失了:

$('#calendar').fullCalendar({
    ...
    refetchResourcesOnNavigate: true,
    resources: '/my-path/resources',
    ...
});

我通过添加自定义今天按钮并重现其功能解决了我的问题。这是一种解决方法,但效果很好。

$('#calendar').fullCalendar({
    customButtons: {
        todayButton: {
            text: 'today'
        }
    },
    header: {
        left: 'todayButton prev,next',
        ...
    },
    ...
});

$(document).on('click', '.fc-todayButton-button', function () {
    var todayDate = moment().format('YYYY-MM-DD');
    $('#calendar').fullCalendar('gotoDate', todayDate);

    + NEEDED ACTIONS FOR RENDERING EVENTS
});

这似乎是一个老问题,但如果有人仍在寻找没有解决方法的解决方案,您可以尝试使用 mousedown 而不是 click,这样它会在 fullcalendar 的默认操作之前触发。

具体来说,这对我有用:

.on('mousedown', '.fc-today-button', function() {
   // something here
})