首页 > 解决方案 > FullCalendar:如何在 eventDrop (node.js) 上保存/发送修改后的事件到数据库或服务

问题描述

我有一个 FullCalendar 对象集成到我的 node.js 解决方案中,它通过来自面向数据库的 REST 服务的 json 接受事件。

一旦将更新的事件拖到新的时间段(在 eventDrop 上),如何将更新的事件保存回中央数据库?

global.js

document.addEventListener('DOMContentLoaded', function() {
  var calendarEl = document.getElementById('calendar'); 
  var calendar = new FullCalendar.Calendar(calendarEl, {
        defaultView: "timeGridWeek",
        height: "auto",
        slotDuration: "00:60:00",
        navLinks: true,
        events: '/classes/jsonlist',
        plugins: [ 'dayGrid', 'timeGrid', 'interaction' ],
        editable: true,
        eventDrop: function(info) {
          var new_event_start_time = info.event.start.toLocaleTimeString();
          if (!confirm("Are you sure you want to move it to "+new_event_start_time+" ?")) {
            info.revert();
          };
//        Update database record for the event
//
        var xhr = $.ajax({
          url: "/classes/jsonset",
          type: "POST",
          contentType: "application/json",
          data: JSON.stringify( { 'id': info.event.id, 'url': info.event.url, 'title': info.event.title,'new_start': info.event.start } ),
          timeout: 5000
        }).done(function( msg ){
              alert( "Data Saved: " + msg );
        });           

        }
      }
    );
  calendar.render();
});

标签: javascriptnode.jsjsonfullcalendarfullcalendar-4

解决方案


推荐阅读