为了账号安全,请及时绑定邮箱和手机立即绑定

将事件开始日期从 FullCalendar 更新到我的数据库结果为 00:00:00

将事件开始日期从 FullCalendar 更新到我的数据库结果为 00:00:00

PHP
慕妹3242003 2023-03-04 17:41:30
当用户在我的日历中拖放事件时,我正在使用 FullCalendar 并尝试更新事件开始时间。这是我使用的附加到 eventDrop 回调的代码(https://fullcalendar.io/docs/eventDrop):        alert(info.event.id + ' was dropped on ' + info.event.start);        $.ajax({          url: '/Post/dropPost',          type: 'POST',          data: { 'postSchedule': info.event.start, 'postId' : info.event.id },        });       },这与警报显示正确的事件 ID 和正确的开始日期(格式如下:2020 年 5 月 5 日星期二 04:36:00)一样有效。'/Post/dropPost' 方法也被调用并且 postId 变量被正常传递。但是,当它更新我的数据库时,postSchedule 总是更新为“00:00:00 00:00:00”。这是我的 dropPost 方法:    public function dropPost()     {        $data=[];        $postSchedule = $_POST['postSchedule'];        $postId = $_POST['postId'];        $droppedPost = new PostModel;        $data['id'] = $postId;        $data['postSchedule'] = $postSchedule;        $droppedPost->save($data);    }通过阅读 FullCalendar 文档,我了解到日期应该始终是 ISO8601 标准: https: //fullcalendar.io/docs/date-parsing。那么为什么它不转化为我的数据库。我数据库中的 postSchedule 列是 DateTime 类型。
查看完整描述

1 回答

?
皈依舞

TA贡献1851条经验 获得超3个赞

我终于找到了答案。我需要在 info.event.start 属性上使用 .toISOString() 。


工作代码如下:


 eventDrop: function(info) {

    alert(info.event.id + ' was dropped on ' + info.event.start);

    $.ajax({

      url: '/Post/dropPost',

      type: 'POST',

      data: { 'postSchedule': info.event.start.toISOString(), 'postId' : info.event.id },

    });

   },


查看完整回答
反对 回复 2023-03-04
  • 1 回答
  • 0 关注
  • 151 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号