【问题标题】:React How can I receive the 3h rain foreact from openweathermap (Identifier directly after number error)React 如何从 openweathermap 接收 3 小时降雨预报(数字错误后直接识别标识符)
【发布时间】:2020-09-26 17:49:33
【问题描述】:

我是编程新手,没有必要的基础知识。 我正在尝试从 OpenWeatherMap 获取下雨数据,但仍然出现错误:

解析错误:标识符直接跟在数字后面。

前两个示例不起作用。我只能对对象进行字符串化。您能否建议输入“.3h”的正确方法是什么?

{test.list.map((item, key) => <p key="{key}">{item.rain.3h}</p>)}

{test.list.map((item, key) => <p key="{key}">{item.rain.["3h"]}</p>)}

{test.list.map((item, key) => <p key="{key}">{JSON.stringify(item.rain)}</p>)}

【问题讨论】:

    标签: reactjs openweathermap


    【解决方案1】:

    错误是因为变量不应该以数字开头,因此,点符号会出错。第二个示例可以通过删除最后一个点来工作,就像这样:

    test.list.map((item, key) => item.rain['3h'])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-24
      • 1970-01-01
      • 2013-09-30
      • 1970-01-01
      • 2014-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多