且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

点击日历时创建带fullcalendar的事件(导轨)

更新时间:2023-02-25 12:33:11

您可以使用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
        }
    );
}