2012-02-02 106 views
11

我一直在使用FullCalendar插件,现在我已经设法使它在FF和Chrome中工作,但我似乎无法理解为什么事件不会在Safari上出现。FullCalendar事件只在Safari上不显示

我正在使用Rails后端将事件作为数组获取。这是FireBug显示的事件的JSON对象。

_end: Invalid Date  
_id: "1953" 
_start: Fri Feb 10 2012 00:00:00 GMT+0530 (IST) 
allDay: false 
backgroundColor: "#F60 !important" 
className: Array[0] 
color: "#FFFFFF !important" 
description: "" 
end: Invalid Date 
start: Fri Feb 10 2012 00:00:00 GMT+0530 (IST) 
textColor: "#FFFFFF !important" 
__proto__: Object 

我在safari控制台上没有错误。无效结束日期在FF和Chrome上显示为null

这是我如何填充

event[:id]      = each_event.id  
event[:title]    = each_event.event_title  
event[:allDay]    = each_event.all_day? 
event[:start]    = each_event.start_time.strftime('%Y-%m-%d %H:%M:00')  
event[:end] = each_event.end_date.to_time.strftime('%Y-%m-%d %H:%M:00') if each_event.end_date.present?   
event[:color]    = '#FFFFFF !important'  
event[:backgroundColor]  = (each_event.user == current_user) ? '#F60 !important' : '#090 !important'   
event[:backgroundColor]  = '#090 !important' unless each_event.private?  
event[:textColor]   = '#FFFFFF !important' 

我试图转换的日期时间,以ISO8601格式太的事件,并没有奏效。我对这个问题是完全无能为力的。我真的很感谢一些帮助。

+0

同样的问题在这里。你有没有设法解决这个问题? – melat0nin 2012-06-07 10:00:21

+2

我一直在使用fullCalendar一段时间,直到这一点,我遇到的所有问题都是日期解析有点不同。例如(Mac上的Safari 6.0(7536.25)) - 新日期('01 -01-2000')无效,因为在其他浏览器中,它是完全有效的。在这些情况下,您应该用正斜杠替换所有连字符,以便结果类似于新日期('01/01/2000')。我希望这是有帮助的。 – woot 2012-08-19 19:10:28

+1

@TomReznik在我的情况下,这是字符串,这个问题让我看到了正确的地方。但它不是破折号与斜线问题,在我的情况下,它用破折号完美地工作。相反,它是当天的格式,我输出一个数字(2012-11-1),缺少的领先0是什么扔掉它。我想这个错误在今年年底时会更常见,我确定这个月有同样的错误,但在10月和11月它没有被注意到。 – DigitalDesignDj 2012-11-09 19:58:23

回答

0

您的字符串格式不正确。

而不是使用

event[:start] = each_event.start_time.strftime('%Y-%m-%d %H:%M:00') 
event[:end] = each_event.end_date.to_time.strftime('%Y-%m-%d %H:%M:00') if each_event.end_date.present? 

尝试使用

event[:start] = each_event.start_time.to_json 
event[:end] = each_event.end_date.to_time.to_json if each_event.end_date.present? 

根据FullCalendar文档的开始和结束的属性需要一个Date对象或IETF格式的字符串,ISO8601格式或UNIX时间戳。因为strftime('%Y-%m-%d %H:%M:00')都不是这些,所以代码将不起作用。

http://arshaw.com/fullcalendar/docs/event_data/Event_Object/

1

我有类似的问题。 我使用的DateTime的.iso8601功能是什么帮助:

event[:start] = each_event.start_time.iso8601 
event[:end] = each_event.end_date.to_time.iso8601 if each_event.end_date.present? 

ISO8601格式给出输出,如:2017-01-25T16:15:49 + 01:00

+0

老问题,但这个答案似乎不错。从rfc822更改为iso8601为我工作。 – 2017-05-05 16:52:05