我正在尝试使用Jquery Fullcalendar创建一个动态日历,我希望在事件中显示不同的标题,如果它们是月,周或日视图。我,尝试使用addEventSource和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不呈现,然后如果标题将根据视图而改变。我会感激任何帮助。
答案 0 :(得分:2)
eventSources
需要是数组,而不仅仅是事件对象。将对象封装在数组中,看看是否有效。
请检查此小提琴以获得演示 - jsfiddle.net/100thGear/CBPW8/1