单击时在FullCalendar中添加事件 [英] Add events in FullCalendar on click

查看:1953
本文介绍了单击时在FullCalendar中添加事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在.NET中的日历单元格上添加事件,如下所示:

I am trying to add events on calendar cell click in .NET like this:

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

我接受了这篇文章的帮助:

I took the help of this post:

点击日历(rails)时使用fullcalendar创建活动

我正在获取警报上的选定日期和文本,无法在选定的单元格上发布..

I am getting the Selected date and text on Alert , bit not able to post it on selected cell ..

我在jsfiddle上尝试了相同的解决方案:

I have tried same solution on jsfiddle:

http://jsfiddle.net/5o66w860/

我的代码:

$(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);

                }

jsfiddle;

jsfiddle ;

http://jsfiddle.net/5o66w860/

这篇关于单击时在FullCalendar中添加事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆