简体   繁体   English

如何以编程方式更新 fullcalendar 中事件的呈现

[英]how to programmatically update the rendering of an event in fullcalendar

I'm working on an app that already renders a calender using fullcalendar, whenever the page refreshes the time slots are always rendered with the correct colors using the event render callback.我正在开发一个已经使用 fullcalendar 呈现日历的应用程序,每当页面刷新时,时间段总是使用事件呈现回调呈现正确的颜色。 It also correctly changes the color of the time slot when the event is clicked upon, using the event click callback.它还使用事件单击回调在单击事件时正确更改时间槽的颜色。

This is all nice, however I'm trying to programmatically manipulate the renderings of the time slots based on some other stuff the user does after the calendar has fully loaded.这一切都很好,但是我正在尝试根据用户日历完全加载所做的其他一些事情,以编程方式操纵时间段的渲染。 In code this is what i'm trying to do在代码中,这就是我想要做的

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()));

    ..

once clicked, the program displays a modal form that the user fills.单击后,程序会显示用户填写的模态表单。 Upon completion and dismissal of the dialog, the clicked event needs to change its color to reflect a change of status, that's where i call this method:完成和关闭对话框后,单击的事件需要更改其颜色以反映状态的更改,这就是我调用此方法的地方:

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

This simply don't work.这根本行不通。 Using Chrome dev tool breakpoints i ensured that the function hideLessonPlan actually talks to the right variables.使用 Chrome 开发工具断点,我确保函数hideLessonPlan实际上与正确的变量对话。

Upon further investigation i realized that in both event render and event click callbacks.. the function updateEvent(event) is called after the background properties have been set.. however in my case.. this event is not called after setting the properties.经过进一步调查,我意识到在event renderevent click回调中.. 在设置背景属性调用函数updateEvent(event) .. 但是在我的情况下.. 在设置属性后调用此事件。 So my question is more of: how can I actually call this upateEvent method from the outside?所以我的问题更多是:我如何从外部实际调用这个 upateEvent 方法? It seems like a private variable.它似乎是一个私有变量。

update: i made it work but simply by storing the css properties of the selected div and then using jquery to find the same div and highlighting it manually afterwords.更新:我使它工作,但只是通过存储所选 div 的 css 属性,然后使用 jquery 查找相同的 div 并在后记中手动突出显示它。 not too happy about this hacky way.. hoping someone would come along and show me how to do it through fullcalendar.对这种 hacky 方式不太满意..希望有人能来告诉我如何通过 fullcalendar 做到这一点。

it turns out that i simply had to update the property of the calendarEvent ie事实证明,我只需要更新 calendarEvent 的属性,即

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

then call update event :然后调用更新事件

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

that took care of all the rendering for me它为我处理了所有渲染

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM