[英]How can I convert Google calendar events to date object for react-big-calendar
So I want to use the week view for RBC. 所以我想使用RBC的周视图。 I keep getting TypeError: date[("get" + method)] is not a function
我一直得到TypeError:date [(“get”+ method)]不是函数
There are a few issue reports that all say that I need a date
object and in fact, I can open the calendar when I use this example 有一些问题报告都说我需要一个
date
对象,事实上,我可以在使用这个例子时打开日历
var myEventsList = [{
{
'title': 'Meeting',
'start': new Date(2017, 3, 12, 10, 30, 0, 0),
'end': new Date(2017, 3, 12, 12, 30, 0, 0),
desc: 'Pre-meeting meeting, to prepare for the meeting'
},
{
'title': 'Lunch',
'start':new Date(2017, 3, 12, 12, 0, 0, 0),
'end': new Date(2017, 3, 12, 13, 0, 0, 0),
desc: 'Power lunch'
}]
So I know that I need to convert my start: 2019-05-14T12:00:00.000Z,
to new Date( x,x,x,x,x)
所以我知道我需要将我的
start: 2019-05-14T12:00:00.000Z,
转换为new Date( x,x,x,x,x)
I've tried doing this on the backend with a thing like this 我试过用这样的东西在后端做这个
for (let i = 0; i < data.length; i++) {
events.push({
title: data[i].summary,
start: new Date(data[i].start.dateTime),
end: new Date(data[i].end.dateTime)
I've also tried moment(data[i].start.dateTime)
along with a host of different google search suggestions with all kinds of .format(), .todate(), etc but I keep getting errors. 我也尝试了
moment(data[i].start.dateTime)
以及各种各样的.format(),. todate()等不同的谷歌搜索建议,但我不断收到错误。
UPDATE : 更新:
I've also tried setting it up in my frontend with this bit 我也尝试用这个位置在我的前端设置它
const events=[]
const makeDatobj = (data) =>{
events.map(event => ({
title : event.title,
start : new Date(event.start)
}));
which I hope to initialize with 我希望初始化
<BigCalendar
...
localizer={localizer}
events={events=>makedatobj(data)}
step={70}
timeslots={2}
defaultView="week"
...
/>
But that gives me TypeError: data.map is not a function
但这给了我
TypeError: data.map is not a function
which just reminds me that I don't know how .map()
Works and I keep coming up against similar issues when I try to use it...I've tried a few other methods of parsing the incoming data with similar degrees of failure. 这只是提醒我,我不知道如何
.map()
工作,当我尝试使用它时,我一直遇到类似的问题......我尝试了一些其他方法来解析传入数据的类似程度失败。 I notice that when I try to process the incoming data, I inadvertently shut off my api request so I don't have any data to work with....I'm really making this way more difficult than it needs to be. 我注意到当我尝试处理传入的数据时,我无意中关闭了我的api请求,所以我没有任何数据可以使用....我真的这样做比实际需要的更困难。
I just need a simple answer. 我只需要一个简单的答案。 How can I convert.
我该如何转换?
start: 2019-05-14T12:00:00.000Z,
to start: new date( x,x,x,x,x)
? start: 2019-05-14T12:00:00.000Z,
开始: new date( x,x,x,x,x)
?
The Date constructor can also take a string as a parameter, so you can do: Date构造函数也可以将字符串作为参数,因此您可以执行以下操作:
start : new Date("2019-05-14T12:00:00.000Z")
So it sounds like your backend should be like this, returning the dates as strings: 所以听起来你的后端应该像这样,将日期作为字符串返回:
for (let i = 0; i < data.length; i++) {
events.push({
title: data[i].summary,
start: data[i].start.dateTime,
end: data[i].end.dateTime
}
And your frontend code should be like this, converting them to Javascript Dates: 你的前端代码应该像这样,将它们转换为Javascript日期:
events.map(event => ({
title : event.title,
start : new Date(event.start)
}));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.