【问题标题】:how to programmatically update the rendering of an event in fullcalendar如何以编程方式更新全日历中事件的呈现
【发布时间】:2014-04-04 05:11:10
【问题描述】:

我正在开发一个已经使用 fullcalendar 呈现日历的应用程序,每当页面刷新时,时隙总是使用 event render 回调以正确的颜色呈现。它还使用event click 回调正确更改单击事件时的时隙颜色。

这一切都很好,但是我正在尝试根据用户在日历完全加载后 执行的其他操作以编程方式操作时隙的渲染。在代码中,这就是我想要做的

var eventClick = function(calEvent, jsEvent, view) {
    // first we change the color of the event to indicate that it was clicked
    calEvent.backgroundColor = orangeColor;
    calEvent.textColor= darkGreyColor;
    calEvent.active=true;
    $(this).css('background', orangeColor).css('color', darkGreyColor);

    // i cache both the calEvent and the element to manipulate them later on
    cachedActiveEvents.push(calEvent);
    // here i'm storing this div: <div class="fc-event fc-event-vert ..>
    //                                <div class="fc-event-inner">
    //                                    <div class="fc-event-time">12:30 - 1:20</div>
    //                                    <div class="fc-event-title">event title</div>
    //                                    ..
    cachedActiveEventViews.push($($(jsEvent.target).parent().parent()));

    ..

单击后,程序会显示一个用户填写的模式表单。对话框完成和关闭后,单击的事件需要更改其颜色以反映状态的更改,这就是我调用此方法的地方:

function hideLessonPlan() {
    ..
    $.map(cachedActiveEvents, function(calEvent, eventIndex) {
        var element = cachedActiveEventViews[eventIndex];
        calEvent.backgroundColor = blackColor;
        calEvent.textColor = "white"
        element.css('background', blackColor).css('color','white');
    });
}

这根本行不通。使用 Chrome 开发工具断点,我确保函数 hideLessonPlan 实际上与正确的变量对话。

经过进一步调查,我意识到在event render 和event click 回调中......函数updateEvent(event) 被调用之后背景属性已经设置......但是在我的情况下......设置属性后不调用此事件。所以我的问题更多的是:我如何才能从外部调用这个 upateEvent 方法?它似乎是一个私有变量。

更新:我让它工作,但只需存储所选 div 的 css 属性,然后使用 jquery 找到相同的 div 并在后面手动突出显示它。对这种 hacky 方式不太满意.. 希望有人能过来告诉我如何通过 fullcalendar 做到这一点。

【问题讨论】:

    标签: javascript jquery events fullcalendar fullcalendar-3


    【解决方案1】:

    原来我只需要更新 calendarEvent ie 的属性

    calEvent.isActive = true; 
    calEvent.status = 0; // ie in progress
    

    然后拨打update event:

    $('#calendar').fullCalendar('updateEvent',calEvent);
    

    它为我处理了所有的渲染

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-07
      • 1970-01-01
      • 2017-07-30
      • 1970-01-01
      相关资源
      最近更新 更多