gpt4 book ai didi

javascript - 如何在数组中呈现当天?

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

我正在从我的应用程序中的 REST API 中提取一些数据,并尝试使用 moment 将当天解析为结果。

这是我的代码示例:

{restaurants.map((item, index) =>
<View key={item.id}>
<Text>
{`item.store_open_close.time.${currentDay.toLowerCase()}.opening_time`}</Text></View>
)}

但这是渲染,例如:item.store_open_close.time.thursday.opening_time

而不是我所期望的,例如:

上午 10:00

我觉得我快到了?任何帮助表示赞赏。谢谢!

PS - 我的餐厅数据如下所示

"store_open_close": {
"enabled": true,
"time": {
"sunday": {
"status": "close",
"opening_time": "",
"closing_time": ""
},
"monday": {
"status": "open",
"opening_time": "10:00 am",
"closing_time": "7:00 pm"
},
"tuesday": {
"status": "open",
"opening_time": "10:00 am",
"closing_time": "7:00 pm"
},
"wednesday": {
"status": "open",
"opening_time": "10:00 am",
"closing_time": "7:00 pm"
},
"thursday": {
"status": "open",
"opening_time": "10:00 am",
"closing_time": "7:00 pm"
},
"friday": {
"status": "open",
"opening_time": "10:00 am",
"closing_time": "7:00 pm"
},
"saturday": {
"status": "open",
"opening_time": "10:00 am",
"closing_time": "7:00 pm"
}
},
"open_notice": "We are open",
"close_notice": "Sorry we are closed"
},

最佳答案

您正在寻找这个:

<Text>{item.store_open_close.time[currentDay.toLowerCase()].opening_time}</Text>

之前您使用的是 string literal并且只在 js 中表达 ${currentDay.toLowerCase()},但你想要整行。

关于javascript - 如何在数组中呈现当天?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58226207/

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