8

I want to update my json in fullcalendar, Here is what I am exactly trying to do. I have a JSON string which I am directly trying to feed in to the event objects in the full calendar.

-->

var JSON[
    {
        "id": "1", // Optional
        "title": "Demo event", // Required
        "start": "2013-08-28 10:20:00", // Required
        "end": "2013-08-28 11:00:00", // Optional
        "allDay": false, // Optional
        "url": "http://google.com", // Optional, will not open because of browser-iframe security issues
        "className": "test-class", // Optional
        "editable": true, // Optional
        "color": "yellow", // Optional
        "borderColor": "red", // Optional
        "backgroundColor": "yellow", // Optional
        "textColor": "green" // Optional
    },
    {
        "id": "2", // Optional
        "title": "Demo event 2", // Required
        "start": "2013-08-27 10:20:00", // Required
        "end": "2013-08-27 11:00:00", // Optional
        "allDay": false, // Optional
        "url": "http://google.com", // Optional, will not open because of browser-iframe security issues
        "className": "test-class", // Optional
        "editable": true, // Optional
        "color": "yellow", // Optional
        "borderColor": "red", // Optional
        "backgroundColor": "yellow", // Optional
        "textColor": "green" // Optional
    }
];

,

Then I want to modify the JSON on some drop down event (not shown in the fiddle) to a new string and try to get the new event on the calendar.

The fullCalendar does not take effect.

http://jsfiddle.net/pratik24/u8Ksw/28/

Thanks for the help. appreciate it.

4

2 回答 2

20

您没有调用正确的 fullCalendar 方法来呈现新事件。

这将不起作用,因为它仅用于第一次呈现事件:

   $("#demo-calendar").fullCalendar('renderEvents', JSON);

相反,您需要删除日历上的事件并刷新它们:

   $("#demo-calendar").fullCalendar('removeEvents'); 
   $("#demo-calendar").fullCalendar('addEventSource', JSON); 

检查小提琴:http: //jsfiddle.net/shaunp/u8Ksw/29/

请注意,有一个名为 的 fullCalendar 方法refetchEvents,但它不适用于诸如您创建的事件数组,因此您必须手动关闭事件并再次重新添加事件源。

于 2013-08-28T21:16:05.443 回答
-1

您需要添加以下几行:

$("#demo-calendar").fullCalendar('removeEvents'); 
$("#demo-calendar").fullCalendar('addEventSource', JSON, true); 

在日历中添加新事件时,它们可能会在切换月份时消失。为了解决这个添加stick: true到被添加到范围的事件对象。

于 2019-02-01T07:45:14.897 回答