点击日历时创建带fullcalendar的事件(导轨) [英] create event with fullcalendar when clicking on calendar (rails)
问题描述
当用户点击日历的任何部分时,您如何创建活动?然后将其作为新事件存储在数据库中?
我知道你必须使用:select:function(start,end,allDay)来获得开始和结束时间。但是,我得到这些数据后,我该如何将它传递给数据库?
谢谢!
您可以使用ajax请求将新事件存储在数据库中。
有一个演示在项目主页上,可以很容易地适应。
通过jQuery例如这样:
select:function(start,end,allDay){
var title = prompt('Event Title:');
if(title){
calendar.fullCalendar('renderEvent',
{
title:title,
start:start,
end:end,
allDay:allDay
},
true //使事件贴
);
/ **
* ajax调用将事件存储在DB
* /
中jQuery.post(
event / new// your url
,{//重复使用事件数据
title:title,
start:start,
end:end,
allDay:allDay
}
) ;
}
calendar.fullCalendar('unselect');
$ b $ p
$ b 如果您需要对特定的点击作出反应,您也可以尝试此操作,但是你必须自己grep事件结束或持续时间。
dayClick:function(date,allDay,jsEvent,view){
var title = prompt('Event Title:');
/ **
*再次:ajax调用将事件存储在DB
* /
jQuery.post(
event / new// your url
,{//重复使用事件数据
title:title,
start:date
allDay:allDay
}
);
}
How do you create an event when the user clicks on any part of the calendar? and then store it in the database as a new event?
I know you have to use: select: function(start, end, allDay) to get the "start" and "end" times. But after I get this data how do I pass it to the database?
Thanks!
解决方案 You may use an ajax request to store the new event in your DB.
There is a demo on the projects homepage, which can easily be adapted.
Via jQuery for example like this :
select: function(start, end, allDay) {
var title = prompt('Event Title:');
if (title) {
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
/**
* ajax call to store event in DB
*/
jQuery.post(
"event/new" // your url
, { // re-use event's data
title: title,
start: start,
end: end,
allDay: allDay
}
);
}
calendar.fullCalendar('unselect');
}
If you need to react on a specific click, you can also try this, but you have to grep the event end or duration by yourself.
dayClick: function(date, allDay, jsEvent, view) {
var title = prompt('Event Title:');
/**
* again : ajax call to store event in DB
*/
jQuery.post(
"event/new" // your url
, { // re-use event's data
title: title,
start: date
allDay: allDay
}
);
}
这篇关于点击日历时创建带fullcalendar的事件(导轨)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!