jQuery FullCalendar没有清除事件

I am currently working away with FullCalendar, which is pretty cool and has done a lot of neat stuff for me. The only problem I'm having is that if I edit an event, and then try and create another event the javascript seems to hold onto the initial events data.

I am using calendar.fullCalendar('unselect') when I need the link to end, but it doesn't seem to make a difference no matter what I do. I'm hoping you guys might be able to see something I'm overlooking.

<script type='text/javascript'>

    $(document).ready(function() {

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

         var calendar = $('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            defaultView: 'agendaWeek',
            selectable: true,
            unselectAuto: true,
            selectHelper: true,
            editable: true,
            select: function(start, end, allDay) {
                //var title = prompt('Event Title:');
                //var desc = prompt('Event Description:');
                //calendar.fullCalendar('unselect');    

                $('#eventStart').val(start);
                $('#eventEnd').val(end);
                $('#eventAllDay').val(allDay);

                $('#formName').fadeIn();

                $('.closeSchedule a').click(function(){
                    $('#formName').fadeOut('slow');

                    $('#calendar').fullCalendar('unselect');    
                    //alert(jsEvent);
                });
            },
            events: [
                <?php

                 $first = true;

                 foreach ($events as $event)
                 {

                    if ($first == true)
                    {
                        $comma = '';
                        $first = false;
                    }
                    else
                    {
                        $comma = ',';
                    }

                     echo $comma."
                     {
                        id: '".$event->id."',
                        title: '".addSlashes($event->title)."',
                        start: '".$event->start."',
                        end: '".$event->end."',
                        allDay: ".$event->allDay."
                    }";
                    $first = false;
                 }

                ?>
                            ],

            eventClick: function(event) {
                //alert(event.id);


                $.ajax({
                  url: './schedule/getEdit/'+event.id,
                  success: function(data) {
                    var formEmpty = $('formName').html();
                    $('#formName').html(data);
                    $('#formName').fadeIn('fast');

                    $('.closeSchedule a').click(function(){
                        $('#formName').fadeOut('slow');
                        $('#calendar').fullCalendar('unselect');
                    });

                    $('#deleteEvent').live('click', function(){
                        var answer = confirm("Are you sure you wish to delete this event?")

                        if (answer){
                            $.ajax({
                               type: "POST",
                               url: "./schedule/deleteEvent/"+event.id,
                               success: function(msg){

                                  $('#formName').fadeOut('fast');            

                                  calendar.fullCalendar( 'removeEvents', [event.id ] )
                                  $('#calendar').fullCalendar('unselect');
                               }
                            });
                        }

                    }); 

                    $('#updateEvent').live('click', function(){

                        var title       = $('#eventName').val();
                        var trainerID   = $('#eventTrainer').val();
                        var trainer     = $('#eventTrainer option:selected').text();
                        var classID     = $('#eventType').val();
                        var eventType   = $('#eventType option:selected').text();
                        var eventStart  = $('#eventStart').val();
                        var eventEnd    = $('#eventEnd').val();
                        var eventAllDay = $('#eventAllDay').val();

                        if (eventAllDay == 'false')
                        {
                            allDay = false;
                        }
                        else
                        {
                            allDay = true;
                        }



                    // This runs the ajax to add the event to the database.
                    newData = 'title='+title+'&trainerID='+trainerID+'&classID='+classID+'&start='+eventStart+'&end='+eventEnd+'&allDay='+allDay

                    $.ajax({
                       type: "POST",
                       url: "./schedule/updateEvent/"+event.id,
                       data: newData,
                       success: function(msg){

                         event.title = title;

                         calendar.fullCalendar('rerenderEvents');

                         //calendar.fullCalendar('unselect');
                         $('#calendar').fullCalendar('unselect');
                       }
                     });



                    $('#formName').fadeOut('fast');
                    $('#eventName').val('');
                    $('#eventTrainer').val();
                    $('#eventType').val();  


                    });
                  }
                });

            },
            eventDrop: function(event,dayDelta,minuteDelta,allDay,revertFunc) {


                    newData = 'start='+event.start+'&end='+event.end+'&allDay='+allDay

                    $.ajax({
                       type: "POST",
                       url: "./schedule/updateEventTime/"+event.id,
                       data: newData,
                       success: function(msg){

                       }
                     }); 
            },
            eventResize: function(event,dayDelta,minuteDelta,revertFunc) {

                newData = 'start='+event.start+'&end='+event.end+'&allDay='+event.allDay

                $.ajax({
                   type: "POST",
                   url: "./schedule/updateEventTime/"+event.id,
                   data: newData,
                   success: function(msg){

                   }
                 }); 

            }
        }); 



        $('#submitEvent').click(function(){
                    $('#calendar').fullCalendar('unselect');
                    var title       = $('#eventName').val();
                    var trainerID   = $('#eventTrainer').val();
                    var trainer     = $('#eventTrainer option:selected').text();
                    var classID     = $('#eventType').val();
                    var eventType   = $('#eventType option:selected').text();
                    var eventStart  = $('#eventStart').val();
                    var eventEnd    = $('#eventEnd').val();
                    var eventAllDay = $('#eventAllDay').val();

                    if (eventAllDay == 'false')
                    {
                        allDay = false;
                    }
                    else
                    {
                        allDay = true;
                    }



                    // This runs the ajax to add the event to the database.
                    newData = 'title='+title+'&trainerID='+trainerID+'&classID='+classID+'&start='+eventStart+'&end='+eventEnd+'&allDay='+allDay

                    $.ajax({
                       type: "POST",
                       url: "./schedule/addEvent",
                       data: newData,
                       success: function(msg){

                         var description = '<ol><li>'+title+'</li><li>'+trainer+'</li><li><a href="#" target="_blank">'+eventType+'</a></li><li class="eventID hide">'+msg+'</li>';

                         calendar.fullCalendar('renderEvent',
                            {
                                id: msg,
                                title: title,
                                description: description,
                                start: eventStart,
                                end: eventEnd,
                                allDay: allDay

                            },
                            true // make the event "stick"
                         );


                         calendar.fullCalendar('unselect');
                         //calendar.fullCalendar( 'rerenderEvents' )
                       }
                     });



                    $('#formName').fadeOut('fast');
                    $('#eventName').val('');
                    $('#eventTrainer option:selected').removeAttr('selected');
                    $('#eventType option:selected').removeAttr('selected');


        });
    });

   </script>

At this point, I feel like I've tried it all, and I'm just hoping a fresh set of eyes will see what I missed.

1个回答



好的,快速查看一下,您似乎没有在“选择”中使用空白表单初始化添加操作的表单: “完整日历的功能:</ p>

在您的活动中单击您执行此操作:</ p>

  $('#formName')。html  (数据); 
</ code> </ pre>

我看不到你用新的事件的空白表格清除它的位置。 (可能刚刚错过了那里有很多代码)</ p>

请告诉我。</ p>
</ div>

展开原文

原文

Ok took a quick look it looks like you aren't initializing the form with a blank form for the add action in the "select:" function of your full calendar:

In your event click you are doing this:

$('#formName').html(data);

I don't see where you are clearing that with a blank form for a new event. (might have just missed it there is a lot of code there)

Let me know.

doupeng5320
doupeng5320 我只想跟进并再次表示感谢! 你派我去了正确的方向。 虽然我正在清理表单,但我忘了我需要做$('#formName')。html(emptyForm); 这返回了添加表单,并删除了编辑表单。 什么东西这么少,直到你发布它我才能看到它。 非常感谢!
9 年多之前 回复
duancaozen6066
duancaozen6066 谢谢你的回复! 虽然这确实遇到了我最终会遇到的问题,但它并没有解决我最初的问题。
9 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐