你需要寫
{
url: 'api/events/get/byrange',
data: {
id: typeof($scope.calendar) == 'undefined' ? '1' : '2'
}
};
沒有在一個變量var eventSource
設置它。相反,只需在FullCalendar初始化中附加這段代碼即可。
但是,我不使用這種方法。相反,我對返回對象列表的操作執行JSON請求。
的Javascript:
$.getJSON('GetCalendar?TrainingId=' + $('#TrainingId').val(), function (response) {
$('#CalendarWrapper').empty();
$('#CalendarWrapper').append("<div id='calendar' name='calendar'></div>");
window.events = response;
window.calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay' //, basicWeek,basicDay
},
selectHelper: true,
allDaySlot: false,
slotDuration: '00:15:00',
buttonIcons: true, // show the prev/next text
weekNumbers: false,
editable: true,
selectOverlap: true,
unselectAuto: true,
eventLimit: true, // allow "more" link when too many events
lang: GetFullCalendarLanguage(),
aspectRatio: 2.5,
events: window.events,
});
_CalendarBuild = true;
})
操作:
[HttpGet]
public JsonResult GetCalendar(int TrainingId)
{
var model = QUERY
.Select(x => new FullCalendar
{
title = x.Module.Description + ", " + x.Local.Info,
Day = x.Day,
(...)
})
.ToList();
return Json(model, JsonRequestBehavior.AllowGet);
}
FullCalendar:
public class FullCalendar
{
public virtual string title { get; set; }
public virtual string url { get; set; }
public virtual DateTime Day { get; set; }
public virtual string start { get; set; }
public virtual string end { get; set; }
public virtual bool startEditable { get; set; }
}
而當我想再次渲染我只需再次調用JavaScript(這是放置在函數內部)。
你可以創建兩個資源,然後以編程方式顯示或隱藏它們嗎?與此類似:http://stackoverflow.com/questions/10940182/change-fullcalendar-event-source-after-render –