Fullcalendar December Issue



在下面的代码下,我一直在使用jQuery fullcalender没有问题。直到12月到来。对于事件功能Calmonth = 0,Calyear =2018。我可以回到11月,一切都很好。我确实有12月的活动...我在做什么错?我知道0 = 1月。

$(document).ready(function() {
var d = new Date();
var $month = (d.getMonth() + 1);
var $year = d.getFullYear();
$("#month").val($month);
$("#year").val($year);
var $timezone = "Central Time Zone";
 $('#calendar').fullCalendar({
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,basicWeek,basicDay'
     },
    events: function (start, end, $timezone, callback) {
        var calMonth = end._d.getMonth();
        var calYear = end._d.getFullYear();
        $("#month").val(calMonth);
        $("#year").val(calYear);
        var edata = JSON.stringify({ month: $("#month").val(), year: $("#year").val() });
        $.ajax({
            type: "POST",
            url: "/Events/GetCalendarData",
            contentType: "application/json; charset=utf-8",
            data: edata,
            dataType: "json",
            success: function (res) {
                callback(res);
            },
            error: function (xhr, status, error) {
                var errorData = xhr.responseText;
            }
        }); 
    },
    eventClick:  function(event, jsEvent, view) {
        $('#modalTitle').html(event.title);
        $('#modalBody').html(decodeURIComponent(event.description));
        $('#fullCalModal').modal();
        if (event.url) {
            return false;
        }
    }       
});

});

控制器操作

 public ActionResult Index()
    {
        var model = new EventsModel();
        return View(model);
    }
    public JsonResult GetCalendarData(int month, int year)
    {
        EventsModel model = new EventsModel();
        return Json(model.GetSchoolEvents(month, year), JsonRequestBehavior.AllowGet);
    }

模型

    public DateTime Start { get; set; }
    public DateTime End { get; set; }
    public string JsonEvents { get; set; }
    public int month { get; set; }
    public int year { get; set; }
    public EventsModel()
    {
        month = DateTime.Now.Month;
        year = DateTime.Now.Year;
        GetSchoolEvents(month, year);
    }
    public bool isAdmin { get; set; }
    public IEnumerable<CalendarEvent> GetSchoolEvents(int month, int year)
    {
        List<DataObjects.Events.Event> eventsList = new List<DataObjects.Events.Event>();
        eventsList = provider.GetEvents(month, year);
        List<CalendarEvent> calendarEvents = new List<CalendarEvent>();
        foreach(var evt in eventsList)
        {
            CalendarEvent calendarEvent = new CalendarEvent()
            {
                start = evt.Start.ToString(),
                end = evt.End.ToString(),
                title = evt.Title,
                description = evt.Description
            };
            calendarEvents.Add(calendarEvent);
        }
        return calendarEvents;
    }

,因此FullCalendar的日期使我失望的方式。这有效:

        events: function (start, end, $timezone, callback) {
        var startDate = new Date(start);
        startDate.setDate(startDate.getDate() + 10);
        var calMonth = startDate.getMonth() + 1;
        var calYear = startDate.getFullYear();
        $("#month").val(calMonth);
        $("#year").val(calYear);

相关内容

  • 没有找到相关文章