0

大家好,感谢您花时间阅读本文。我正在使用 jquery callendar 并且我正在尝试构建自定义视图,如果我正在使用议程周视图查看该周中的所有天,我正在徘徊我如何才能在未来仅阻止日历一周?我的意思是,我只希望它在未来一周内显示,不再显示。这是我的配置;

$('#calendar').fullCalendar({
            header: {
                left: 'next today',
                center: 'title',
                right: 'week'
            },
                        defaultView: 'basicWeek',
            editable: true,
            events: [<?php echo $calendar_events?>
                                ]
                    });

    });

谢谢大家先进

4

1 回答 1

1

周视图中 1 周阻塞的简单解决方案。要使此代码正常工作,您需要来自http://www.merlyn.demon.co.uk/weekcalc.htm#WNR的 getWeekNumber 函数

/* For a given date, get the ISO week number
*
* Based on information at:
*
*    http://www.merlyn.demon.co.uk/weekcalc.htm#WNR
*
* Algorithm is to find nearest thursday, it's year
* is the year of the week number. Then get weeks
* between that date and the first day of that year.
*
* Note that dates in one year can be weeks of previous
* or next year, overlap is up to 3 days.
*
* e.g. 2014/12/29 is Monday in week  1 of 2015
*      2012/1/1   is Sunday in week 52 of 2011
*/
function getWeekNumber(d) {
   // Copy date so don't modify original
   d = new Date(d);
   d.setHours(0,0,0);
   // Set to nearest Thursday: current date + 4 - current day number
   // Make Sunday's day number 7
   d.setDate(d.getDate() + 4 - (d.getDay()||7));
   // Get first day of year
   var yearStart = new Date(d.getFullYear(),0,1);
   // Calculate full weeks to nearest Thursday
   var weekNo = Math.ceil(( ( (d - yearStart) / 86400000) + 1)/7)
   // Return array of year and week number
   return [d.getFullYear(), weekNo];
}

您需要做的是在加载视图后检查当前周数:

$('.calendar-container').fullCalendar({
    viewDisplay: function(view) {
        var selectedWeekNumber = getWeekNumber($('.calendar-container').fullCalendar('getView').start);
        var currentWeekNumber = getWeekNumber(new Date());

        if (selectedWeekNumber[1] == currentWeekNumber[1]) {
            $('a.date-link.prev').hide();
            $('a.date-link.next').show();
        } else {
            $('a.date-link.prev').show();
            $('a.date-link.next').hide();
        }
    }
});
于 2013-01-03T15:51:38.713 回答