我正在尝试使用 jQuery Fullcalendar 制作动态日历,如果它们在月、周或日视图中,我想在事件上显示不同的标题。我正在尝试使用addEventSource
and removeEventSource
,但我无法让事件获得渲染。这是我的代码:
<script type='text/javascript'>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
daySource = new Object();
daySource.title = 'MONTH'; // this should be string
daySource.start = new Date(y, m, d); // this should be date object
daySource.end = new Date(y, m, d);
var day =new Array();
day[0]= daySource;
monthSource = new Object();
monthSource.title = 'MONTH'; // this should be string
monthSource.start = new Date(y, m, d); // this should be date object
monthSource.end = new Date(y, m, d);
var month =new Array();
month[0]= monthSource;
$('#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',
viewDisplay: function(view) {
if (lastView == undefined) { lastView = 'firstRun'; }
if (view.name != lastView ) {
if (view.name == 'agendaWeek') {
$('#calendar').fullCalendar( 'addEventSource', month );
$('#calendar').fullCalendar( 'removeEventSource', day );
$('#calendar').fullCalendar( 'removeEventSource', day );
$('#calendar').fullCalendar('renderEvents');
}
if (view.name == 'agendaDay') {
$('#calendar').fullCalendar( 'addEventSource', day );
$('#calendar').fullCalendar( 'removeEventSource', month );
$('#calendar').fullCalendar( 'removeEventSource', month );
$('#calendar').fullCalendar('renderEvents');
}
if (view.name == 'month') {
$('#calendar').fullCalendar( 'addEventSource', month );
$('#calendar').fullCalendar( 'removeEventSource', day );
$('#calendar').fullCalendar( 'removeEventSource', day );
$('#calendar').fullCalendar('renderEvents');
}
lastView = view.name;
}
},
timeFormat: { // for event elements
agendaDay: '',
agendaWeek: '',
month: '',
'': 'h(:mm)t' // default
},
}); $('#calendar').fullCalendar( 'addEventSource', month ); $('#calendar').fullCalendar('rerenderEvents');
});
首先我不知道为什么 avents 不渲染,然后标题是否会根据视图而改变。我会很感激任何帮助。