gpt4 book ai didi

fullcalendar - 如何为每个 View 加载不同的事件源(json)?

转载 作者:行者123 更新时间:2023-12-02 08:55:02 25 4
gpt4 key购买 nike

嗨,我有一个日历,它必须为每个 View 加载不同的 JSON 事件源。即,“月”的简要来源(每天单元格最多只有 3 个项目),然后是“日”和“周”的更详细的数据来源。

我想我可以捕获 View 何时加载,并根据哪个 View ,调用 removeEventSource() 删除先前的事件源,然后调用 addEventSource() 添加当前 View 的相关数据并刷新。这是做这样的事情的唯一方法吗?如果是这样...我如何检测 View 已完成加载,以便我可以调用 getView() 来加载适当的事件源?

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

感谢您的帮助

编辑:我能想到的唯一其他方法是删除“日/周/月”全日历按钮,并用我自己的按钮替换,该按钮会重新加载 php 屏幕,并附加一个变量,例如 &calLoad=month 或 &calLoad=day 然后我可以加载不同的 json feed,但这显然是一种不太理想的处理方式。

最佳答案

有趣的是我只是 posted an answer to an entirely different question这恰好是解决这个问题的方法。正如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>

关于fullcalendar - 如何为每个 View 加载不同的事件源(json)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5575935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com