无法通过ajax在jquery fullcalendar中设置动态数据

时间:2022-12-04 16:05:51

can somebody tell me how to populate "jquery fullcalendar" events using ajax.

有人可以告诉我如何使用ajax填充“jquery fullcalendar”事件。

There is no setter method provided in fullcalendar to set ajax response (which is Json object) after calendar object loads. Is there any way to feed data after calendar object loads?

fullcalendar中没有提供setter方法来在日历对象加载后设置ajax响应(它是Json对象)。有没有办法在日历对象加载后提供数据?

In my case very first time I provide data in fullcalendar "event:" property and it is working fine. But when I press next or previous to switch one month to another, I'm unable to feed data into that.

在我的情况下,我第一次在fullcalendar“event:”属性中提供数据,它工作正常。但是当我按下一个或上一个月切换到另一个月时,我无法将数据输入到那个月。

Thnx in advance

Thnx提前

2 个解决方案

#1


1  

in ASP.NET MVC View:

在ASP.NET MVC视图中:

$('#calendar').fullCalendar({
            theme: true,
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            events: "/Calendar/GetEvents/"});

Contoller:

位指示:

public JsonResult GetEvents()
    {
        List<DAL.VwMeeting> allMeeting = meetingRepository.GetAll();
        var eventList = from e in allMeeting
                        select new
                        {
                            url=(e.MeetingOccurID).ToString(),
                            title = e.MeetingTitle,
                            start = ConvertToUnixTimestamp((DateTime)e.MeetingOccurStartDate),
                            end = ConvertToUnixTimestamp((DateTime)e.MeetingOccurEndTime),
                            allDay = false
                        };
        return Json(eventList.ToArray());
    }

or you can use:

或者您可以使用:

$('#calendar').fullCalendar('refetchEvents');

after each event handle

每个事件处理后

#2


1  

Rather than fetching the events by Ajax and then putting them in the calendar, you can use the fullcalendar to do all of the Ajax for you:

您可以使用fullcalendar为您执行所有Ajax,而不是通过Ajax获取事件然后将它们放入日历中:

$('#calendar').fullCalendar({
    events: "/myfeed.php"
});

Then the correct events will be fetched according to the range of dates the user is viewing. See the fullcalendar documentation for more info.

然后将根据用户正在查看的日期范围获取正确的事件。有关详细信息,请参阅fullcalendar文档。

#1


1  

in ASP.NET MVC View:

在ASP.NET MVC视图中:

$('#calendar').fullCalendar({
            theme: true,
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            events: "/Calendar/GetEvents/"});

Contoller:

位指示:

public JsonResult GetEvents()
    {
        List<DAL.VwMeeting> allMeeting = meetingRepository.GetAll();
        var eventList = from e in allMeeting
                        select new
                        {
                            url=(e.MeetingOccurID).ToString(),
                            title = e.MeetingTitle,
                            start = ConvertToUnixTimestamp((DateTime)e.MeetingOccurStartDate),
                            end = ConvertToUnixTimestamp((DateTime)e.MeetingOccurEndTime),
                            allDay = false
                        };
        return Json(eventList.ToArray());
    }

or you can use:

或者您可以使用:

$('#calendar').fullCalendar('refetchEvents');

after each event handle

每个事件处理后

#2


1  

Rather than fetching the events by Ajax and then putting them in the calendar, you can use the fullcalendar to do all of the Ajax for you:

您可以使用fullcalendar为您执行所有Ajax,而不是通过Ajax获取事件然后将它们放入日历中:

$('#calendar').fullCalendar({
    events: "/myfeed.php"
});

Then the correct events will be fetched according to the range of dates the user is viewing. See the fullcalendar documentation for more info.

然后将根据用户正在查看的日期范围获取正确的事件。有关详细信息,请参阅fullcalendar文档。