【发布时间】:2021-04-21 04:17:47
【问题描述】:
当我控制台从从后端获取数据的函数返回的数据时出现此错误
{“_U”:0,“_V”:0,“_W”:空,“_X”:空}
下面是代码:
const events_data = [];
function getvals() {
return fetch('http://PCIP:3000/users/timetable')
.then((response) => response.json())
.then((output) => {
return addData(output, events_data);
})
.catch(error => console.log(error))
}
function addData(data, data2) {
data.map((d) => {
data2.push({
title: d.name,
startTime: genTimeBlock(d.day, d.start_time),
endTime: genTimeBlock(d.day, d.end_time),
location: d.location,
extra_descriptions: [d.extra_descriptions],
});
});
}
const data = getvals();
console.log(data); // the error come from here
我在这里检查了答案,但对我没有任何帮助
fetch API always returns {“_U”: 0, “_V”: 0, “_W”: null, “_X”: null}
How do I access promise callback value outside of the function?
【问题讨论】:
标签: json react-native fetch-api