简体   繁体   English

如何更新fullCalendar中的事件?

[英]how to update an event in fullCalendar?

I want to update my json in fullcalendar, Here is what I am exactly trying to do. 我想在fullcalendar中更新我的json,这是我正在尝试做的事情。 I have a JSON string which I am directly trying to feed in to the event objects in the full calendar. 我有一个JSON字符串,我直接尝试输入完整日历中的事件对象。

--> - >

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. 然后我想将一些下拉事件(未在小提琴中显示)上的JSON修改为新字符串并尝试在日历上获取新事件。

The fullCalendar does not take effect. fullCalendar不会生效。

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

Thanks for the help. 谢谢您的帮助。 appreciate it. 欣赏它。

You aren't calling the correct fullCalendar method to render the new events. 您没有调用正确的fullCalendar方法来呈现新事件。

This will not work because it is only meant to render the events the first time around: 这不起作用,因为它只是为了第一次渲染事件:

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

Instead you need to remove the events on the calendar and refresh them: 相反,您需要删除日历上的事件并刷新它们:

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

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

NOTE that there is a fullCalendar method called refetchEvents , but that it does NOT work on an array of events such as what you have created, so you must manually take the events off and re-add the event source again. 请注意 ,有一个名为refetchEvents的fullCalendar方法,但它不适用于您创建的事件数组,因此您必须手动关闭事件并再次重新添加事件源。

You need to add the following lines: 您需要添加以下行:

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

When adding new events to the calendar they can disappear when switching months. 将新事件添加到日历时,它们可能会在切换月份时消失。 To solve this add stick: true to the event object being added to the scope. 要解决此问题,请添加stick: true对添加到范围的事件对象为stick: true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM