如何为每个视图加载不同的事件源(json)? [英] How to load different Event source (json) for each View?

查看:118
本文介绍了如何为每个视图加载不同的事件源(json)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有一个日历,它必须为每个视图加载不同的JSON事件源。即Month的简要来源(每天最多只有3件物品),然后是Day和Week的更详细的数据来源。

我想我可以捕获何时加载视图,并基于哪个视图调用 removeEventSource()来移除前一个事件源,然后 addEventSource ()添加当前视图的相关数据并刷新。
这是做这种事情的唯一方法吗?如果是的话...我如何检测视图已完成加载,所以我可以调用 getView()来加载相应的事件源?



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



感谢您的帮助



编辑:我可以想到做的唯一的另一种方式是删除日/星期/月fullcalendar按钮,并用我自己的替换重新加载php屏幕与变量附加说& calLoad =月或& calLoad = day 然后我可以使用不同的json feed加载,但这显然是一个不太理想的做事方式。

方案

有趣的是,我只是发布了一个完全不同的问题的答案,这恰好是解决方案对此。我使用 addEventSource ()和 removeEventSource()方法,正如OP考虑的那样。

 < script> 
var fcSources = {
课程:{
url:base +'accessfm / calendar / courses',
类型:'GET',
缓存:true,
错误:函数(){警报('有事打破课程...'); },
颜色:'purple',
textColor:'white',
className:'course'
},
请求:{
url:基础+'accessfm /日历/请求',
类型:'GET',
缓存:真实,
错误:函数(){警报('某事破坏了请求...'); },
textColor:'white',
className:'requests'
},
加载:{
url:base +'accessfm / calendar / loads',
类型:'GET',
缓存:true,
错误:function(){alert('有些东西破坏了加载...'); },
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){//视图已被修改,调整设置
if( fullCalendar('removeEventSource',fcSources.loads)
.fullCalendar('refetchEvents');;
} view.name =='month'){
$('#fullcalendar'
if(view.name!='month'&& lastView =='month'){
$('#fullcalendar')。fullCalendar('addEventSource',fcSources.loads);
}
}
la stView = view.name;
}
});
< / script>


Hi i have a calendar which must load a different JSON source of events for each view. ie, A brief source for "Month" (only a max of 3 items per day cell), then more detailed sources of data for both "Day" and "Week".

I was thinking i could capture when a view has loaded and based on which view, call removeEventSource() to remove the previous event source then addEventSource() to add the current view's related data and refresh. Is this the only way to do something like this? If so... how do i detect that the view has finished loading so i can call getView() to inturn load the appropriate event source?

I've seen there is loading() callback but i don't think this is what i need, i want to know when the whole calendar is complete loading not just the current data.

Thanks for any help

EDIT: The only other way I can think to do this is remove the DAY/WEEK/MONTH fullcalendar buttons and replace with my own which reloads the php screen with a variable appended say &calLoad=month or &calLoad=day i can then load with a different json feed but this is obviously a less optimal way of doing things.

解决方案

Funnily enough I just posted an answer to an entirely different question that happens to be the solution to this. I used the addEventSource() and removeEventSource() methods, as the OP considered.

<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>

这篇关于如何为每个视图加载不同的事件源(json)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆