我试图从python文档中设置计时器的值,我的问题是,在获取数据之后,如何插入每个区域的时间?
fetch('https://python document/')
.then((data) => data.json())
//
.then((data) =>
console.log(data)
//do I have to pass it on from here to the array below?
)
//
.catch(error =>{
console.log('does not work!');
})
};
const allAreas = [
createArea('area-1', whatever we get from the python will set the time here in minutes, ex 60 * 60),
createArea('area-2', and here ex 10* 60),
createArea('area-3', and here ex 20 * 60),
createArea('area-4', and here ex 30* 60),
createArea('area-5', and here ex 40* 60),
createArea('area-6', and here ex 50 * 60),
createArea('area-7', and here ex 90 * 60),
createArea('area-12', and here ex 120 * 60),
];我不确定如何将从fetch请求获得的值传递给数组。
请帮帮忙。
发布于 2022-08-01 15:31:14
这在很大程度上取决于您正在获取的数据的结构方式。
这也取决于您到底想要实现什么,您希望数组中的值在任何时候都存在吗?
您希望保留此功能吗?重新加载页面或网站的各种页面(假设您正在创建某种网站)。
最简单的方法就是这样做,->
const createArea = function (area, timer) {
console.log(area, timer) // Your logic here...
}
let allAreas = []
fetch('https://dummyjson.com/products/1')
.then(res => res.json())
.then(json => {allAreas.push(createArea('area-5', (json.price * 60)))})https://stackoverflow.com/questions/73194902
复制相似问题