gpt4 book ai didi

javascript - 解构 - 错误重复声明 'hour'

转载 作者:行者123 更新时间:2023-11-30 11:25:02 25 4
gpt4 key购买 nike

我正在使用解构来创建开始和结束时间:

  const {
startYear: year,
startMonth: month,
startDay: day,
startHour: hour,
startMinute: minute
} = event.start_date_details;
const {
endHour: hour,
endMinute: minute
} = event.end_date_details;

有什么想法吗?

事件 json:

  "events": [
{
"id": 518,
"global_id": "wordpress.rguc.co.uk?id=518",
"global_id_lineage": [
"wordpress.rguc.co.uk?id=518"
],
"author": "1",
"status": "publish",
"date": "2017-12-14 12:11:42",
"date_utc": "2017-12-14 12:11:42",
"modified": "2018-01-11 10:04:49",
"modified_utc": "2018-01-11 10:04:49",
"url": "http://wordpress.rguc.co.uk/event/another-one/",
"rest_url": "http://wordpress.rguc.co.uk/wp-json/tribe/events/v1/events/518",
"title": "another one",
"description": "",
"excerpt": "",
"image": false,
"all_day": true,
"start_date": "2018-01-31 00:00:00",
"start_date_details": {
"year": "2018",
"month": "01",
"day": "31",
"hour": "00",
"minutes": "00",
"seconds": "00"
},
"end_date": "2018-01-31 23:59:59",
"end_date_details": {
"year": "2018",
"month": "01",
"day": "31",
"hour": "23",
"minutes": "59",
"seconds": "59"
},
"utc_start_date": "2018-01-31 00:00:00",
"utc_start_date_details": {
"year": "2018",
"month": "01",
"day": "31",
"hour": "00",
"minutes": "00",
"seconds": "00"
},
"utc_end_date": "2018-01-31 23:59:59",
"utc_end_date_details": {
"year": "2018",
"month": "01",
"day": "31",
"hour": "23",
"minutes": "59",
"seconds": "59"
},

最佳答案

解构的语法(顺便说一句,解构是错误的术语)是不同的。您需要指定在冒号之前匹配的键和在冒号之后声明的变量。也许你想要:

 const {
year: startYear,
month: startMonth,
day: startDay,
hour: startHour,
minutes: startMinute
} = event.start_date_details;
const {
hour: endHour,
minutes: endMinute
} = event.end_date_details;

关于javascript - 解构 - 错误重复声明 'hour',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48343032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com