【问题标题】:Full calendar events disappearing when using multiple calendars - Meteor使用多个日历时完整的日历事件消失 - Meteor
【发布时间】:2015-06-25 10:45:51
【问题描述】:

我想在我的 Meteor 应用程序中使用 Fullcalendar 在一个页面上显示多个项目的日程安排。每个项目都有自己的基本周历视图和自己的事件。当只渲染一个日历时,我能够让日历按预期工作。

对于多个日历,事件会在首次渲染时显示,但在重新获取事件时会消失。我有一个自定义按钮,可以同时更改每个日历的星期。改变几周后,事件消失了。使用单个日历时,相同的功能可以正常工作。我参考了 George McKnight 的视频作为起始参考:https://www.youtube.com/watch?v=e2jRxw0saRc

我认为在 for 循环中呈现多个日历是个问题。我已经看到一些论坛讨论事件“坚持”选项,但我没有遇到事件随着一个日历消失的问题,我认为这不是问题。我还看到一些谈话指向我尝试事件源,但不确定如何在我的用例中应用它。

这是我的代码的 sn-p:

Template.ScheduleAdminTest.rendered = function () {
    var orgId = UserProfiles.findOne({userId:Meteor.userId()}).orgId;
    var items = Items.find({}, {reactive: false}).fetch();
    
    // INITIALIZE VARIABLES
    var itemId;
    var events;
    var itemReservations;

    // RENDER CALENDAR FOR EACH ITEM
    for (var i = 0; i < items.length; i++) {
        itemId = items[i]._id;

        $('#calendar-'+itemId).fullCalendar({
            header:  false,
            firstDay: 0, // SUNDAY
            contentHeight: 100,
            eventLimit: true,
            defaultView: 'basicWeek',
            views: {
                week: {
                    eventLimit: 5
                }
            },
            editable: false,
            eventColor: '#2BA9A5',
            events: function(start, end, timezone, callback) {
                events = [];
                itemReservations = ItemReservation.find({itemId: itemId}, {reactive:false});
                
                itemReservations.forEach(function(reservation) {
                    events.push({
                        id: reservation._id,
                        title: reservation.title,
                        start: reservation.start,
                        end: reservation.end,
                        quoteId: reservation.quoteId,
                        itemId: reservation.itemId,
                    });
                });

                callback(events);
            },
            eventClick: function(calEvent, jsEvent, view) {
                // code for rendering a modal for editing and reviewing events
            },
            dayClick: function( date, jsEvent, view) {   
                // code to display modal for adding an event
            }

        });  // end calendar set

    } // end for loop for items
};

【问题讨论】:

  • $('#calendar-' +vehicleId) 中的vehicleId 来自哪里?如果未定义,则您的目标是具有相同 id 'calendar-' 的多个元素,并可能将新更新推送到其中的第一个
  • 哎呀!抱歉,我在简化代码 sn-p 时错过了该编辑。在此示例中为 itemId。不错的收获。

标签: javascript jquery meteor calendar fullcalendar


【解决方案1】:

在每个日历被渲染后试试这个:

  $('#calendar-'+itemId).fullCalendar('removeEvents');
  $('#calendar-'+itemId).fullCalendar('addEventSource', events)

【讨论】:

  • 嗯,这是我以前的进步。当我至少改变几周时,这些事件仍然存在,但现在当我点击我得到的事件时:'未捕获的 RangeError:超过最大调用堆栈大小'。这可能与我的事件单击功能有关,因为当我将其注释掉时,错误就会消失。我会再调查一些。
  • 另外,我在进行更改时无法让日历响应式更新。使用单个日历,此代码有效:Deps.autorun(function() { Items.find({}).fetch(); $('.item-calendar').fullCalendar('refetchEvents'); // common class for all calendars });
  • 所以发生了调用堆栈错误,因为所有日历事件似乎都存储在 calEvents 的某些子属性中。在设置我在其他计算中使用的会话变量之前,我最终抓住了我需要的字段,从而解决了这个问题。使用 'addEventSource' 方法的 .fullCalendar('refetch events') 函数仍然存在问题。有什么建议吗?
  • 知道了!最终完全删除 events.option 并将所有逻辑移动到 Deps.autorun 中,我使用了您推荐的“removeEvents”和“addEventSource”函数。
猜你喜欢
  • 1970-01-01
  • 2018-05-27
  • 1970-01-01
  • 2016-04-24
  • 1970-01-01
  • 1970-01-01
  • 2017-06-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多