【问题标题】:FULLCALENDAR V5 format date insert eventFULLCALENDAR V5 格式日期插入事件
【发布时间】:2022-12-01 16:52:40
【问题描述】:

我正在用最新版本的 fullcalendar 重写我的日历,问题是我必须通过 ajax / json 在数据库中插入事件,javascript 中的开始和结束变量给我无效的日期,尽管使用了新的 formatdate 方法,我我做错了什么?这是我的代码:

document.addEventListener('DOMContentLoaded', function() {
        var calendarEl = document.getElementById('calendar');
        var calendar = new FullCalendar.Calendar(calendarEl, {
          initialView: 'dayGridMonth',
          firstDay: 1,
          editable: true,
          headerToolbar: {
            left: 'title',
            center: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek',
            right: 'addEvent,today,prev,next'
          }, // buttons for switching between views
         events: '/sistema/app/config/opt/agenda/load.php',
         selectable:true,
        eventColor: '#378006',
        allDaySlot: true,
        scrollTime :  "08:00:00",
        dayMaxEvents: true,
        allDayText: calendar_lang.allDayText,
        buttonText: calendar_lang.buttonText,
        timeZone: 'local',
        locale: 'it',
        
    customButtons: {
    addEvent: {
      text: 'Evento',
      click: function() {
        var dateStr = prompt('Enter a date in YYYY-MM-DD format');
        var date = new Date(dateStr + 'T00:00:00'); // will be in local time

        if (!isNaN(date.valueOf())) { // valid?
          calendar.addEvent({
            title: 'dynamic event',
            start: date,
            allDay: true
          });
          alert('Great. Now, update your database...');
        } else {
          alert('Invalid date.');
        }
      }
    }
  },
  
select: function(start, end, allDay)
{
console.log(start);
 var start = moment(start, 'DD.MM.YYYY').format('YYYY-MM-DD HH:mm:ss')
 var end = moment(end, 'DD.MM.YYYY').format('YYYY-MM-DD HH:mm:ss')
 var testo = prompt("Enter Event Testo");
 var testo_privato = prompt("Enter Event Testo Privato");
 if(testo || testo_privato)
 {
 var idutente = '<?=$idutente?>';
 var title = '<?=$autore?>';
 var groupcode = '<?=$groupcode?>';
 var tipo = "Annotazione";
 console.log("--------------------------------------");


 console.log(start);
  console.log(end);
      $.ajax({
       url:"/sistema/app/config/opt/agenda/insert.php",
       type:"POST",
       data:{idutente:idutente, title:title, testo:testo, testo_privato:testo_privato, tipo:tipo, start:start, end:end, groupcode:groupcode},
       success:function()
       {
        calendar.refetchEvents();
       }
      })
     }
    },
     });
        calendar.setOption('locale', 'it');
        calendar.render();
        
      });

【问题讨论】:

  • 我假设我们正在谈论传递给select回调的日期?不是很清楚。您需要查看该选项的最新文档,因为您使用的是旧语法:fullcalendar.io/docs/select-callback
  • 是的,没错,也许我表达得有点糟糕,事实上我无法从日历中选择日期和时间然后进行插入,我什至不知道文档中有什么错误。
  • 好吧,将您的代码与文档示例和字段列表进行比较……select: function(start, end, allDay)select: function(selectionInfo) 匹配吗……是还是不是?文档在哪里说在新版本中提供了开始和结束属性?

标签: javascript php json ajax fullcalendar


【解决方案1】:
select: function (date) {
console.log(date);
start:date.startStr, end:date.endStr
}

【讨论】:

    猜你喜欢
    • 2015-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    相关资源
    最近更新 更多