可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Is it possible to discover/extract the currently displayed events from the FullCalendar object, (ref: http://arshaw.com/fullcalendar)?
Ideally, I'd like a secondary display for events, alongside the calendar, which should show only the currently displayed events, (e.g. if the calendar is on "March 2012", I only want to see March 2012 events in the secondary list).
I'm guessing I'll nedd to construct some sort of filter, but was hoping I might be able to pull the details straight back off the calendar. I figure the plugin must already have established which are valid for display...
Any pointers to a function/property I've missed would be greatly appreciated.
回答1:
Yes this is surprisingly hard to do. I've been digging around in FullCalendar a lot recently as I've been hacking a load of extra functionality into it for my own purposes. It doesn't store the information internally in that form but you can get at it with a small hack:
Insert at line 4243 (in fullcalendar 1.5.2)
t.eventResize = eventResize //add starts t.getShownEvents = function () { evs = []; for (id in eventElementsByID) evs = evs.concat(eventsByID[id]); return evs; } //add ends
Then do this to get an array of event objects currently being displayed:
var evs = $('#calendar').fullCalendar('getView').getShownEvents();
回答2:
with version 2.x you can filter all client events loaded so far by the current view's intervalStart & intervalEnd - I use a factory function getIdOrFilter to do so
App.getIdOrFilter = function () { var view = $('#calendar').fullCalendar('getView'); var start = view.intervalStart; var end = view.intervalEnd; return function (e) { // this is our event filter if (e.start >= start && e.end <= end) { // event e is within the view interval return true; } // event e is not within the current displayed interval return false; }; } ... var events = $('#calendar').fullCalendar('clientEvents', App.getIdOrFilter());
回答3:
Thanks to James Ellis-Jones, I implemented this on a fork of the Full Calendar resourceviews and sent a pull request to the Full Calendar resourceViews owner.
https://github.com/stephenreid/fullcalendar/commit/808a0ac2ff8e9f900af263049cc95a7d4e2b6546