2017-09-09 4 views
0

FullCalendarから動的に選択したイベントを削除しようとしています。このイベントは、それはまた、すべての行の終わりに削除ボタンで表に表示されるレンダリングさFullCalendar:ボタンクリック時にイベントを削除する

enter image description here

enter image description here

私がしたいことは、削除ボタンをクリックするとカレンダーの予定も削除されます。 テーブルから行を削除できますが、カレンダーでは削除できません。ここ

はイベント

var eventID = 0; 
$('.calendar').fullCalendar({ 
    select: function(start, end, event, view, resource) { 
      if(start.isBefore(moment())) { 
       $('.calendar').fullCalendar('unselect'); 
       swal('Ooops!','You cannot select past date/time!','error') 
      }else{ 
       $('#reserved_date').val(moment(start).format("YYYY-MM-DD")) 
       $('#end_time').val(moment(end).format("hh:mm A")); 
       $('#start_time').val(moment(start).format("hh:mm A")); 
       $('#newScheduleModal').modal({ 
        show : true, 
        backdrop: 'static', 
        keyboard: false 
       }); 
       eventData = { 
        id: eventID +1, 
        title: 'Lesson Schedule', 
        start: start, 
        end: end, 
       }; 
      } 
      $(".fc-highlight").css("background", "red"); 

    }, 
    events: obj, 
    eventRender:function(ev, element) { 
     eventID++; 
     $('#sched_data').append('<tr class="tb-row">'+ 
      '<td>'+moment(ev.start).format('MMM. DD, YYYY')+'</td>'+ 
      '<td>'+moment(ev.start).format('hh:mm A')+'</td>'+ 
      '<td>'+moment(ev.end).format('hh:mm A')+'</td>'+ 
      '<td><button class="btn btn-danger btn-del btn-xs" data-id"'+ev._id+'"><i class="fa fa-times"></i></button></td></tr>' 
     ) 
    }, 

}) 

を選択するための私のコードはここに

$('#btn-reserve').click(function(){ 
     $('.calendar').fullCalendar('renderEvent', eventData, true); 

}) 

をカレンダーにイベントをレンダリングするためのコードだと、ここでイベント

$('body').on('click','.btn-del',function(){ 
    $(this).closest('.tb-row').remove(); 
    $('.calendar').fullCalendar('removeEvents', $(this).data('id')); 
    }) 
+0

あなたの問題は何ですか? – IzumiSy

答えて

0

を削除するための私のコードですされます私はすでにそれをした、

私のコード:それは2番目のパラメータは機能していない単なるIDでなければなりません

$('body').on('click','.btn-del',function(){ 
    var del_btn = $(this); 
    del_btn.closest('.tb-row').remove(); 

    $(".calendar").fullCalendar('removeEvents', function(event) { 
     return event.id == del_btn.data('id'); 
    }); 
}) 

どうあるべきか

$('body').on('click','.btn-del',function(){ 
    $(this).closest('.tb-row').remove(); 
    $('.calendar').fullCalendar('removeEvents', $(this).data('id')); 
}) 

関連する問題