问题描述
我想全日历更新json,这正是我要尝试做的事情.我有一个JSON字符串,我直接尝试将其输入整个日历中的事件对象.
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
}
];
然后,我想将某些下拉事件(小提琴中未显示)的JSON修改为新字符串,并尝试在日历上获取新事件.
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.
fullCalendar无效.
The fullCalendar does not take effect.
http://jsfiddle.net/pratik24/u8Ksw/28/
感谢您的帮助.感谢它.
Thanks for the help. appreciate it.
推荐答案
您没有调用正确的fullCalendar方法来呈现新事件.
You aren't calling the correct fullCalendar method to render the new events.
这将不起作用,因为它仅用于第一次渲染事件:
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);
检查小提琴: http://jsfiddle.net/shaunp/u8Ksw/29/
注意,有一个名为refetchEvents
的fullCalendar方法,但是它不适用于一系列事件(如您创建的事件),因此必须手动取消并重新启动事件. -再次添加事件源.
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.
这篇关于如何更新fullCalendar中的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!