【发布时间】:2021-05-22 15:55:26
【问题描述】:
我是 JS 和 reactJS 的新人。
我想从 API 获取信息到数组。我制作了显示数据库中所有信息的 API。
它看起来像这样:
const [tempNew, setTempNew] = useState([]);
const getAllWeatherCelsius = () => {
fetch('http://localhost:5000/weather')
.then(response => {
return response.json();
})
.then((jsonData) => {
let tmpArray = [];
for (var i = 0; i < jsonData.length; i++) {
tmpArray.push(jsonData.dayCelsius[i]) <---- here is the error
}
setTempNew(tmpArray);
})
}
我想将 "dayCelsius" 行中的所有值收集到数组中。
我需要在此代码中更改什么?谢谢你:)
【问题讨论】:
标签: javascript node.js reactjs api fetch