当用户在我的日历中拖放事件时,我正在使用 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 },
});
},
- 1 回答
- 0 关注
- 151 浏览
添加回答
举报
0/150
提交
取消