我正在从我的应用程序中的REST API中提取一些数据,并且尝试使用时间将当天解析为结果。
这是我的代码示例:
{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"
},
答案 0 :(得分:4)
您正在寻找这个:
<Text>{item.store_open_close.time[currentDay.toLowerCase()].opening_time}</Text>
以前,您使用的是string literal,只在js中表示${currentDay.toLowerCase()}
,但是您需要完整的一行。