jquery - 渲染后更改 Fullcalendar 事件源

标签 jquery fullcalendar fullcalendar-1

我一直在使用 FullCalendar v1.5.3 来替代 MS SharePoint。

我正在尝试重新渲染日历事件的源。例如,当页面默认加载时,这是 ajax 调用

/calendar/events/feedTasks?start=1338094800&end=1341118800&_=1339103302326

我们使用选择框将事件源更改为仅显示任务(从不同的表中提取),因此在选择后,ajax 调用将更改为:

/calendar/events/feedEvents?start=1338094800&end=1341118800&_=1339103302326

这有效。但是,它不仅仅是更改当前日历事件源,而是创建一个重复的日历表(在当前日历表的顶部创建一个新的 div class="fc-content"div)。

这是我到目前为止所拥有的:

$("#TaskSelector").change(onSelectChange);   
    function onSelectChange(){
        $('#calendar').fullCalendar({
            events: '/calendar/events/' + $('#TaskSelector').val()
        });
    }
});

我错过了什么?

最佳答案

有一些名为 removeEventSource() 的方法和addEventSource()允许您调整源列表。我遇到过类似的情况,我需要在月 View 中隐藏其中一个源,但在其他上下文中显示它,我发现删除并重新添加 eventSources 数组中的元素是实现此目的的最干净的方法。

    var fcSources = {
        courses: {
                    url: base+'accessfm/calendar/courses',
                    type: 'GET',
                    cache: true,
                    error: function() { alert('something broke with courses...'); },
                    color: 'purple',
                    textColor: 'white',
                    className: 'course'
                },
        requests: {
                    url: base+'accessfm/calendar/requests',
                    type: 'GET',
                    cache: true,
                    error: function() { alert('something broke with requests...'); },
                    textColor: 'white',
                    className: 'requests'
                },
        loads:  {
                    url: base+'accessfm/calendar/loads',
                    type: 'GET',
                    cache: true,
                    error: function() { alert('something broke with loads...'); },
                    color: 'blue',
                    textColor: 'white',
                    className: 'loads'
                }
    };
<snip>
    $('#fullcalendar').fullCalendar({
        header: {
                    left: 'title',
                    center: 'agendaDay,agendaWeek,month',
                    right: 'today prev,next'
                },
        defaultView: 'agendaWeek',
        firstDay: 1,
        theme: true,
        eventSources: [ fcSources.courses, fcSources.requests, fcSources.loads ],
        viewDisplay: function(view) {
            if (lastView != view.name){ // view has been changed, tweak settings
                if (view.name == 'month'){
                    $('#fullcalendar').fullCalendar( 'removeEventSource', fcSources.loads )
                                      .fullCalendar( 'refetchEvents' );;
                }
                if (view.name != 'month' && lastView == 'month'){
                    $('#fullcalendar').fullCalendar( 'addEventSource', fcSources.loads );
                }
            }
            lastView = view.name;
        }
    });

不要只是复制/粘贴此代码,因为它并不能完全解决您的问题。但你应该能够从中汲取一些想法。调整fcSources散列以适合您的源,然后仅使用其中一个源实例化您的 fullCalendar 对象,并使用 removeEventSource 交换它。和addEventSource方法。

另请注意 refetchEvents() 的使用- 这是确保正确重新渲染显示所必需的。

关于jquery - 渲染后更改 Fullcalendar 事件源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10940182/

相关文章:

javascript - 通过将事件拖到完整日历 V 2 之外来删除事件(带或不带垃圾桶图标...)

javascript - 如何将 JSON 值发送到 FullCalendar 并在日历中显示事件

jQuery 圆形 slider ?

Fullcalendar 事件 url - 如果 url 包含则添加类

php - Ajax 实时搜索 - 获取 2 个字段而不是 1 个

html - 修复了使用多个 Fullcalendars 滚动的标题

jquery - 如何使全日历中过去的日期不可选择?

jquery - 使用 jquery 选择有序列表的列表项 <li>?

jquery - 仅使用 jquery 获取被 css 隐藏的可见单词