完整日历如果开始与结束日期相同(Full Calendar if start is same with end dates)

编程入门 行业动态 更新时间:2024-10-26 00:31:49
完整日历如果开始与结束日期相同(Full Calendar if start is same with end dates)

我有完整的日历,当获取事件的数据时,我在此行中收到错误

end: event.end.format() || event.start.format(),

未捕获的TypeError:无法读取未定义的属性“格式”

根据这个

解决方法是

eventClick: function(event) { var start = event.start; var end = event.end || start; }

但它对我没有用

在完整日历中处理结束日期的最佳方法是什么

eventData = {
  id: id,
  sysid: sysid,
  title: title,
  start: event.start.format(),
  end: event.end.format() || event.start.format(),
  description: description,
  otherinformation: otherinformation,
  page: page,
  action: action

};

I have full calendar and when getting the data for event I get error in this line

end: event.end.format() || event.start.format(),

saying

Uncaught TypeError: Cannot read property 'format' of undefined

According to this

a work around is

eventClick: function(event) { var start = event.start; var end = event.end || start; }

but it didnt work for me

What is the best way to handle end date in full calendar

eventData = {
  id: id,
  sysid: sysid,
  title: title,
  start: event.start.format(),
  end: event.end.format() || event.start.format(),
  description: description,
  otherinformation: otherinformation,
  page: page,
  action: action

};

                

最满意答案

您的实现问题是它检查格式化值的真实性 ,它不评估event.end是否真实 。 所以当event.end评估为falsey ,抛出错误。

你应该检查event.end是否真实 ,因此使用

end: (event.end || event.start).format()

或者,正如API Docs所建议的那样

var start = event.start; var end = event.end || start; eventData = { end: end.format(), };

Problem with your implementation is it checks for truthy ofthe formatted value, it doesn't evaluate whether event.end is truthy. So when event.end evaluated to falsey the error is thrown.

You should check for event.end to be truthy, thus use

end: (event.end || event.start).format()

Or, As suggest by API Docs

var start = event.start; var end = event.end || start; eventData = { end: end.format(), };

更多推荐

本文发布于:2023-08-05 21:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437879.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日历   完整   日期   结束   start

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!