【问题标题】:Editing all day fullCalendar event converts it to a non allDay event编辑全天 fullCalendar 事件会将其转换为非 allDay 事件
【发布时间】:2015-01-18 03:53:32
【问题描述】:

当我编辑全天活动时,fullCalendar (2.0.2) 会将其转换为非全天活动。在日历视图中单击事件时,我会加载一个允许用户编辑详细信息的模式。选择 allDay 或 time 不是其中的一部分,但 date 是。单击提交后,我会触发一个 AJAX 调用,该调用会更新事件服务器端,然后返回包含事件 ID 的 JSON 数据。然后我查询 fullCalendar 以获取正确的事件。此时allDay_allDay都还是true

theEvent = $('#calendar').fullCalendar('clientEvents', data.id)[0];
> theEvent.allDay
true
> theEvent._allDay
true

然后我用编辑后的事件对象更新 fullCalendar:

calendar.fullCalendar('updateEvent', theEvent);

编辑完成后,事件会显示在日历中,12a 会显示在事件标题之前。

我能够追踪到 fullCalendar 中的 mutateEvent 函数,该函数似乎在以下条件下覆盖了我的设置:

// current values are:
// event.allDay: true
// oldAllDay: true
// newStart: Moment object - Mon Jan 19 2015 00:00:00 GMT-0600 (CST)
// newEnd: null

// detect new allDay
if (event.allDay != oldAllDay) { // if value has changed, use it
    newAllDay = event.allDay;
} else { // otherwise, see if any of the new dates are allDay
    newAllDay = !(newStart || newEnd).hasTime();
}

我不认为我做错了什么,但我不能确定。有人对此有意见吗?请和谢谢。目前我无法升级到更新的版本,因为这个版本 (2.0.2) 似乎与我的客户选择的 Ace Admin Bootstrap 主题有些关联。

或者,我希望能够只允许 allDay 事件,这样我以后就不必担心这个了。

【问题讨论】:

  • 你试过最新版本吗?我知道你说它可能与你的模板有关;但也许值得一试,看看它是否是在新版本中修复的错误。然后,您可以决定如何升级它和模板(如果它有效)。

标签: fullcalendar


【解决方案1】:

虽然这并不能真正解决问题,但这个答案解决了我的问题。

只需将 fullCalendar timeFormat 属性设置为 ''。就我而言,我只有一整天的活动,所以我永远不需要时间。

http://fullcalendar.io/docs/text/timeFormat/

$('#calendar').fullCalendar({
    events: [
        {
            title:  'My Event',
            start:  '2010-01-01T14:30:00',
            allDay: false
        }
        // other events here...
    ],
    timeFormat: ''
});

【讨论】:

【解决方案2】:

这似乎是在更高版本中修复的错误。最新版本does it differently

发生的情况是,当您更改开始或结束日期时,它会设置 allDay=false并且更改的日期有时间。问题转载here

解决方案非常简单,当事件是全天时删除开始/结束的时间部分。反正它不应该在那里。

var fcEvent = $('#calendar').fullCalendar("clientEvents",id)[0]; //get the event

// Change the start date and turn it into a string, stripping off the time.
fcEvent.start = moment().format("YYYY-MM-DD"); 

$('#calendar').fullCalendar("updateEvent",fcEvent);

JSFiddle Demo

让它有条件,if(fcEvent.allDay),它应该可以在不破坏其他功能的情况下解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-13
    • 1970-01-01
    相关资源
    最近更新 更多