jQuery 当月份变化时加载完整日历事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9929804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 11:28:44  来源:igfitidea点击:

loading fullcalendar events when the month changes

jqueryfullcalendar

提问by Greg

So I'm a little unsure about how to structure my calendar events with fullcalendar. Currently, when my app loads I'm injecting a json events object into the body of my page, allowing me to init the full calendar quickly, and without an ajax call. On all subsequent month view changes I want to send an ajax request with the given month as an argument so I can pull in that months events. How would I go about doing this? Is this the lazyLoad feature? How can I get the calendar to use the local event data when it initially displays, but then use ajax requests for all subsequent months?

所以我有点不确定如何使用 fullcalendar 来组织我的日历事件。目前,当我的应用程序加载时,我将一个 json 事件对象注入到我的页面正文中,这样我就可以快速初始化整个日历,而无需 ajax 调用。在所有随后的月视图更改中,我想发送一个以给定月份为参数的 ajax 请求,以便我可以提取该月份的事件。我该怎么做呢?这是lazyLoad 功能吗?如何让日历在最初显示时使用本地事件数据,然后在所有后续月份使用 ajax 请求?

回答by Ike

Please note in the latest version the viewDisplay has been replaced with viewRender Find how to use it here

请注意,在最新版本中,viewDisplay 已被 viewRender 替换,请在此处 查看如何使用它

I use it like this

我像这样使用它

        viewRender: function (view, element) {
        }

You can get the start date and end date like this. view.start, view.end

您可以像这样获取开始日期和结束日期。查看.开始,查看.结束

回答by zlosim

try to read the docs, events (as a json feed)
other option is refetch/render events every time date has changed viewDisplay

尝试阅读文档,事件(作为 json 提要)
其他选项是每次日期更改时重新获取/呈现事件viewDisplay

回答by phil294

When the json feed (mentioned by zlosim) does not seem to be enough for your ajax, you can either

当 json 提要(由 zlosim 提到)似乎不足以满足您的 ajax 时,您可以

  • use https://fullcalendar.io/docs/events-functionwhich will be called whenever new data is required. This, however, caches the data internally it seems and the events for one day will not be requested twice. Also, the returned object is not reactive, seems to be cloned.
  • use a plain array for events, but pass a datesRendercallback: https://fullcalendar.io/docs/datesRenderyou can then change your events array appropriately. This is called every time the visible dates change without caching.
  • 使用https://fullcalendar.io/docs/events-function,每当需要新数据时都会调用它。然而,这似乎在内部缓存了数据,并且一天的事件不会被请求两次。此外,返回的对象不是反应性的,似乎是克隆的。
  • 对事件使用普通数组,但传递datesRender回调:https: //fullcalendar.io/docs/datesRender,然后您可以适当地更改事件数组。每次可见日期更改而不缓存时都会调用此方法。