2016-12-05 50 views
0

我想删除事件,当我点击按钮“x”,但不工作,并没有得到任何错误。fullcalendar,删除按钮上的事件点击

我分配在参数“eventRender”功能点击。

这是我的代码用JavaScript:

$('#calendar').fullCalendar({ 
     locale: 'es', 
     weekends: false, //ocultar fines de semana 
     defaultView: 'agendaWeek', 
     allDaySlot: false, 
     header: { 
      left: 'month,agendaWeek,agendaDay,listDay', 
      center: 'title', 
      right: 'prev,next today' 
     }, 
     height: 'auto', 
     minTime: "10:00:00", 
     maxTime: "20:00:00", 
     editable: true, 
     //droppable: true, // this allows things to be dropped onto the calendar 
     dayClick: function(date, jsEvent, view) { 
      console.log('Clicked on: ' + date.format()); 
      console.log('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY); 
      console.log('Current view: ' + view.name); 
      var hoy = moment(); 
      if(date.format("YYYY-MM-DD HH:mm") >= hoy.format("YYYY-MM-DD HH:mm")){ 
       asignarCita(date); 
      }else{ 
       swal({ 
        title: "Cita no disponible", 
        text: "La fecha u hora seleccionada ya ha pasado." 
       }); 
      } 
     }, 
     eventRender: function(event, element) { 
      element.prepend("<div class='ibox-tools'><a style='background-color: transparent; margin-right: 10px' class='pull-left'><i class='fa fa-times closeon'></i></a></div>"); 
      //element.append("<span class='closeon'>X</span>"); 
      console.log(element.find('closeon')); 
      element.find(".closeon").click(function() { 
       $('#calendar').fullCalendar('removeEvents',event._id); 
      }); 
     }, 
     events: [ 
      { 
       title: 'All Day Event', 
       start: '2014-10-01' 
      }, 
      { 
       title: 'Long Event', 
       start: '2014-10-07', 
       end: '2014-10-10' 
      }, 
      { 
       id: 999, 
       title: 'Repeating Event', 
       start: '2014-10-09T16:00:00' 
      }, 
     ], 
    }); 

问题出在哪里?谢谢! 没有得到它的工作

回答

5

试试这个:

eventRender: function(event, element, view) { 
     if (view.name == 'listDay') { 
      element.find(".fc-list-item-time").append("<span class='closeon'>X</span>"); 
     } else { 
      element.find(".fc-content").prepend("<span class='closeon'>X</span>"); 
     } 
     element.find(".closeon").on('click', function() { 
      $('#calendar').fullCalendar('removeEvents',event._id); 
      console.log('delete'); 
      }); 
    }, 

https://jsfiddle.net/vc9ytv2k/

最好的问候!
克日什托夫·

+0

非常感谢您!是的,这项工作(: –

+0

我很高兴我可以帮助! –