如何为每个视图加载不同的事件源(json)?

wir*_*d00 2 fullcalendar

嗨,我有一个日历,必须为每个视图加载不同的JSON事件源.即,"月"的简短来源(每天最多只有3个单元格),然后是"日"和"周"的更详细的数据来源.

我想我可以在视图加载时捕获并基于哪个视图,调用removeEventSource()删除先前的事件源然后addEventSource()添加当前视图的相关数据并刷新.这是做这样事的唯一方法吗?如果是这样的话......我怎么检测到视图已经完成加载所以我可以调用getView()inturn加载适当的事件源?

我已经看到有loading()回调,但我不认为这是我需要的,我想知道整个日历何时完成加载不仅仅是当前的数据.

谢谢你的帮助

编辑:我能想到的唯一另一种方法是删除DAY/WEEK/MONTH fullcalendar按钮并替换为我自己的重新加载php屏幕的变量附加说&calLoad=month or &calLoad=day我可以加载不同的json feed但这显然是一种不太理想的做事方式.

RET*_*RET 6

有趣的是,我刚刚发布了一个完全不同的问题的答案,恰好是解决方案.我考虑了OP,使用了addEventSource()和removeEventSource()方法.

<script>
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'
            }
};
$('#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;
    }
});
</script>
Run Code Online (Sandbox Code Playgroud)