我需要重新获取完整日历的事件,不仅在日历按钮上,而且在我自己的下拉更改中,因为它们定义了事件搜索的标准。到目前为止,我可以使用 传递下拉列表值的唯一方法$.ajax
,但现在事件没有进入日历。我遗漏了一些东西,因为我似乎并不完全理解该功能。
$(function () {
InitializeCalendar();
$("#ProjectId").change(function () {
$('#calendar').fullCalendar('refetchEvents');
});
$("#JobId").change(function () {
$('#calendar').fullCalendar('refetchEvents');
});
$("#StoreId").change(function () {
$('#calendar').fullCalendar('refetchEvents');
});
$("#OrderType").change(function () {
$('#calendar').fullCalendar('refetchEvents');
});
$("#ShippingId").change(function () {
$('#calendar').fullCalendar('refetchEvents');
});
});
function InitializeCalendar() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
events: function (start, end) {
$.ajax({
url: '/Calendar/GetEvents/',
dataType: 'json',
data: {
start: Math.round(start.getTime() / 1000),
end: Math.round(end.getTime() / 1000),
projectId: $("#ProjectId option:selected").val(),
storeId: $("#StoreId option:selected").val(),
jobId: $("#JobId option:selected").val(),
orderType: $("#OrderType option:selected").val(),
shippingId: $("#ShippingId option:selected").val()
}
**SOMETHING MISSING HERE**
//this puts calendar into infinite loop
//$('#calendar').fullCalendar('refetchEvents');
});
}
});
}
控制器:
public JsonResult GetEvents(double start, double end, int? projectId, int? storeId, string orderType, int? shippingId, int? jobId)
{
// Some code...
IList<OrderEvent> events = orderDTOs.Select(orderDTO => new OrderEvent {
id = orderDTO.OrderId,
title = orderDTO.OrderId.ToString(),
start = ToUnixTimespan(orderDTO.CreatedDate),
end = ToUnixTimespan(orderDTO.CreatedDate.AddHours(1)),
url = "/Order/Search"
}).ToList();
return Json(events, JsonRequestBehavior.AllowGet);
}