如何访问收集的 jQuery FullCalendar 事件数据?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7046519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to access collected jQuery FullCalendar event data?
提问by Neil
I work on a project that is based on the draggable events demo concept. I would like to be able to access the events data that has been collected as you add events to the calendar.
我从事一个基于可拖动事件演示概念的项目。我希望能够访问在您向日历添加事件时收集的事件数据。
Is there a hook to access all the data that's been collected? I'm thinking something like:
是否有一个钩子可以访问收集到的所有数据?我在想这样的事情:
$('#calendar').fullCalendar.getEvents();
I'd like to have a button call on the page outside of the calendar that gets all the data that has been collected and sends it back to the server as a string of JSON.
我想在日历外的页面上有一个按钮调用,以获取已收集的所有数据并将其作为 JSON 字符串发送回服务器。
回答by Lobstrosity
回答by Ragupathy
Use this code
使用此代码
$("#btnClear").click(function () {
var events = $('#calendar').fullCalendar('clientEvents');
for (var i = 0; i < events.length; i++) {
var start_date = new Date(events[i].start._d);
var end_date = '';
if (events[i].end != null) {
end_date = new Date(events[i].end._d);
}
var title = events[i].title;
var st_day = start_date.getDate();
var st_monthIndex = start_date.getMonth() + 1;
var st_year = start_date.getFullYear();
var en_day ='';
var en_monthIndex = '';
var en_year = '';
if (end_date != '') {
en_day = end_date.getDate()-1;
en_monthIndex = end_date.getMonth()+1;
en_year = end_date.getFullYear();
}
console.log('Title-'+title+', start Date-' + st_year + '-' + st_monthIndex + '-' + st_day + ' , End Date-' + en_year + '-' + en_monthIndex + '-' + en_day);
}
});