Fra*_*ser 1 javascript jquery fullcalendar
我使用以下代码初始化jQuery FullCalendar.
但是,并非所有月份都有任何事件.我希望日历的初始月份视图是活动的第一个月.
举个例子.目前是六月,日历中没有任何事件直到八月,所以我希望日历的初始视图默认为八月而不是六月.
同样,如果6月份有ARE事件,我希望它默认为6月.
$('#fullCalendar').fullCalendar({
selectable: true,
selectHelper: true,
header: {
left: 'prev',
center: 'title',
right: 'next'
},
events: function(start, end, callback) {
$.getJSON(jSONCalendarURL, {
token:jSONAPItoken,
productID: $('#fullCalendar').attr("data-id"),
startDate: $.fullCalendar.formatDate(start, 'yyyy-MM-dd'),
endDate: $.fullCalendar.formatDate(end, 'yyyy-MM-dd')
}, function(data){
var calevents = [];
$.each(data.response, function(index,item){
calDate = index;
child = item.Variations;
if (child.length > 0 ){
if (!$.isEmptyObject(child)){
calPrice = child[0].Price;
calID = child[0].ID;
calAvailable = child[0].Available;
calevents.push({
'id': calID,
'title': buildEventTitle(calAvailable,calDate.substring(calDate.length,calDate.length-2),child[0].Price, calID, child[0].RRP),
'start': $.fullCalendar.parseDate(calDate),
'end': $.fullCalendar.parseDate(calDate),
'allDay': true
});
}
}
});
callback(calevents);
highlightExisting();
}
);
},
eventRender: function (event, element, view) {
if (event.start.getMonth() != view.start.getMonth())
return false;
},
weekMode:'liquid'
});
Run Code Online (Sandbox Code Playgroud)
我想要做到的是可以实现的吗?
绝对可以实现!您需要首先开始对事件数组进行排序并查找下一个已注册的事件对象.然后,您可以使用.fullCalendar('gotoDate')方法跳转到该日期.
像这样的东西:
function custom_sort(a, b) {
return new Date(a.start).getTime() - new Date(b.start).getTime();
}
events_array.sort(custom_sort);
$('#calendar').fullCalendar('gotoDate', events_array[0].start);
Run Code Online (Sandbox Code Playgroud)
请参考此FIDDLE以获取有效的静态示例.
希望这可以帮助!