FullCalendar - extract displayed events

社会主义新天地 提交于 2019-12-07 10:08:28

问题


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



来源:https://stackoverflow.com/questions/9121425/fullcalendar-extract-displayed-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!