var calendar = $('#calendar').fullCalendar({
//关键在这里,处理events数据
events: function (start, end, timezone, callback) {
var sD = start._i;
var eD = end._i;
var eventsData = [];
$.getJSON("data.json",function(res){
let thisDate = new Date(item.pdtime2).getTime();
//将当前视图的数据取出来
if(sD<=thisDate && thisDate <=eD){
eventsData.push(item);
}
});
//这个回调方法会将数据填到日历里,并重新渲染
callback(eventsData);
},
eventMouseEnter: function(date, allDay, jsEvent, view) {
},
dayClick:function(date, allDay, jsEvent, view){
var date1 = $.fullCalendar.formatDate(date, "YYYY年M月D日");
$("#goDate").val(date);
var nowDate = new Date();
nowDate = nowDate.getFullYear()+'年'+(nowDate.getMonth()+1)+'月'+(nowDate.getDate()+'日');
var res = datas({"reltime":date1}).get();
var str = "";
for(let i=0;i<res.length;i++){
str+='<div class="box-s">'+
'<span class="time-s">'+ res[i].start +'-'+ res[i].end +'</span>'+
'<span>'+ res[i].title +'</span>';
if(res[i].isactive){
str+='<span class="live-s"><a href="'+ res[i].video +'" target="_blank"><img src="/images/live.gif" alt="" /></a></span>';
}
str+='</div>';
}
$("#dateContent").html(str);
},
eventClick: function(event, jsEvent) { //日程事件点击
alert(event.title);
},
eventMouseover: function(){}, //鼠标划过和离开的事件,用法和参数同上
eventMouseout: function(){},
});
这里写了部分的关键代码, 主要是处理events数据。供大家参考
借鉴博客: FullCalendar: 动态获取数据_scut_少东的博客-CSDN博客_fullcalendar 重新渲染