简体   繁体   English

FullCalendar-仅请求当月的事件

[英]FullCalendar - Only request events for current month

My database has many events, so I'd only like to request events for the current month that the user is on to make load time faster. 我的数据库有很多事件,所以我只想请求用户当前月份的事件,以加快加载时间。

The events are loaded from a php script: 这些事件是从php脚本加载的:

$(document).ready(function() {
    $('#fullcalendar').fullCalendar({
        navLinks: true,
        editable: true,
        eventLimit: true, 
        defaultTimedEventDuration: '00:15:00',
        events: '<?php echo $cal_root;?>/_calendar/load_calendar.php?month_and_year=',  
    });

});

So I need to pass the month and year that the user is on to the php script to request the relevant events for that month, is there a way this can be done? 因此,我需要将用户所在的月份和年份传递给php脚本,以请求该月份的相关事件,有没有办法做到这一点?

I just discovered that start and end variables are sent automatically when requesting the events via ajax. 我刚刚发现,通过ajax请求事件时,会自动发送start和end变量。

So I didn't have to add anything to the Fullcalendar code, I just had to pick up those variables with my PHP script, eg $_GET['start'] and $_GET['end'] 因此,我不必在Fullcalendar代码中添加任何内容,只需要使用我的PHP脚本来选择这些变量,例如$_GET['start']$_GET['end']

I had a same problem. 我有同样的问题。 I suggest this method . 我建议这种方法 As the document says: 如文件所述:

This callback will get triggered when the user changes the view, or when any of the date navigation methods are called . 当用户改变视图,或任何日期的导航方法被调用 时,这个回调将得到触发。 This callback will trigger after the view has been fully rendered, but before events have been rendered (see also: eventAfterAllRender). 该回调将在完全渲染视图之后但在事件渲染之前触发(另请参见:eventAfterAllRender)。

So method is call after the first render, and every render when the navigation is called (change the week or change the view). 因此在第一个渲染之后调用方法,并在调用导航时调用每个渲染(更改星期或更改视图)。 From the view object you can get the start and the end visible day, so you can get the events from your DB dynamically. 您可以从视图对象获得可见的开始和结束日期,因此可以动态地从数据库获取事件。

It helped me, I hope it helps you as well. 它对我有所帮助,希望对您也有帮助。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM