当用户单击日/周/月按钮时,我需要运行一些 Javascript 代码来重新加载日历。有没有类似的回调dayButtonClicked()
或者其他的东西?
BUG发生:
当我第一次加载日历时。最初的视图看起来不错,我的最初加载日。一旦我加载另一个视图,例如周。每个条目都是重复的并显示两个数据源。如果我再次在日和月之间单击后退和前进,数据就会恢复正常。正在发生的事情是removeEventSource
当它每天点击后第一次加载新视图时,不会被调用。你以前见过这种情况吗?
<script type='text/javascript'>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var loadUrl = "menu_booking.php?ne=1&calsub=1";
var lastView;
var fullSource = "../fullcalendar/json-events.php?idc=<?= $sClient ?>&v=long";
var liteSource = "../fullcalendar/json-events.php?idc=<?= $sClient ?>";
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
columnFormat: {
month: 'ddd',
week: 'ddd d/M',
day: 'dddd d/M'
},
defaultView: 'agendaDay',
firstDay: 1,
//editable: true,
selectable: true,
allDaySlot: false,
firstHour: 7,
viewDisplay: function(view) {
if (lastView == undefined) { lastView = 'firstRun'; }
if (view.name != lastView ) {
if (view.name == 'agendaWeek') {
$('#calendar').fullCalendar( 'removeEventSource', fullSource );
$('#calendar').fullCalendar( 'removeEventSource', liteSource );
$('#calendar').fullCalendar( 'addEventSource', fullSource );
}
if (view.name == 'agendaDay') {
$('#calendar').fullCalendar( 'removeEventSource', fullSource );
$('#calendar').fullCalendar( 'removeEventSource', liteSource );
$('#calendar').fullCalendar( 'addEventSource', liteSource );
}
if (view.name == 'month') {
$('#calendar').fullCalendar( 'removeEventSource', fullSource );
$('#calendar').fullCalendar( 'removeEventSource', liteSource );
$('#calendar').fullCalendar( 'addEventSource', fullSource );
}
lastView = view.name;
}
},
timeFormat: { // for event elements
agendaDay: '',
agendaWeek: '',
month: '',
'': 'h(:mm)t' // default
},
});
//$('#calendar').limitEvents(2);
});
</script>
我什至按照您的操作方式复制了您的代码,因为我认为我的代码有问题;即使我改成这样:
//VIEW CHANGE - ALSO ADDS INITIAL SOURCES PER DAY VIEW
viewDisplay: function(view) {
$('#calendar').fullCalendar( 'removeEventSource', fullSource );
$('#calendar').fullCalendar( 'removeEventSource', liteSource );
$('#calendar').fullCalendar( 'addEventSource', fullSource ); }
},
当我从默认加载的视图移动到另一个视图时,它仍然会双重加载数据。我开始认为这肯定是一个错误FullCalendar
。这让我发疯
EDIT 2:我的上帝。我不敢相信它终于起作用了!
我不知道为什么,但我需要交换addEventSource
and removeEventSource
现在看起来像这样:
viewDisplay: function(view) {
if (lastView == undefined) { lastView = 'firstRun'; }
//alert("viewname: "+ view.name + "lastView: " + lastView);
if (view.name != lastView ) {
if (view.name == 'agendaWeek') {
$('#calendar').fullCalendar( 'addEventSource', shortSource );
$('#calendar').fullCalendar( 'removeEventSource', longSource );
$('#calendar').fullCalendar( 'removeEventSource', shortSource );
}
if (view.name == 'agendaDay') {
//alert("in day: add litesource");
$('#calendar').fullCalendar( 'addEventSource', longSource );
$('#calendar').fullCalendar( 'removeEventSource', longSource );
$('#calendar').fullCalendar( 'removeEventSource', shortSource );
}
if (view.name == 'month') {
//alert("in month: Delete litesource");
$('#calendar').fullCalendar( 'addEventSource', shortSource );
$('#calendar').fullCalendar( 'removeEventSource', longSource );
$('#calendar').fullCalendar( 'removeEventSource', shortSource );
}
lastView = view.name;
}
},