简体   繁体   English

单击即可在 FullCalendar 中添加事件

[英]Add events in FullCalendar on click

I am trying to add events on calendar cell click in .NET like this:我正在尝试在 .NET 中的日历单元格中添加事件,如下所示:

http://arshaw.com/js/fullcalendar-1.5.3/demos/selectable.html http://arshaw.com/js/fullcalendar-1.5.3/demos/selectable.html

I took the help of this post:我接受了这篇文章的帮助:

create event with fullcalendar when clicking on calendar (rails) 单击日历(rails)时使用 fullcalendar 创建事件

I am getting the Selected date and text on Alert , bit not able to post it on selected cell ..我在 Alert 上收到了选定的日期和文本,有点无法将其发布在选定的单元格上..

I have tried same solution on jsfiddle:我在 jsfiddle 上尝试过相同的解决方案:

http://jsfiddle.net/5o66w860/ http://jsfiddle.net/5o66w860/

My code:我的代码:

$(document).ready(function() {

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    var events_array = [
        {
        title: 'Test1',
        start: new Date(2012, 8, 20),
        tip: 'Personal tip 1'},
    {
        title: 'Test2',
        start: new Date(2012, 8, 21),
        tip: 'Personal tip 2'}
    ];

    $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        selectable: true,
        events: events_array,
        eventRender: function(event, element) {
            element.attr('title', event.tip);
        },
        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');
}

    });
});

I also to remove , events array .我也删除了,事件数组。 .. but still not working ..但仍然无法正常工作

Ok , got It after some googling :好的,在谷歌搜索后得到了它:

Just need to change Code on select只需要在选择时更改代码

select: function (start, end, jsEvent, view) {
                    var abc = prompt('Enter Title');
                    var allDay = !start.hasTime && !end.hasTime;
                    var newEvent = new Object();
                    newEvent.title = abc;
                    newEvent.start = moment(start).format();
                    newEvent.allDay = false;
                    $('#calendar').fullCalendar('renderEvent', newEvent);

                }

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

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