首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用获取的数据设置数组的定时器的值?

如何使用获取的数据设置数组的定时器的值?
EN

Stack Overflow用户
提问于 2022-08-01 14:01:26
回答 1查看 41关注 0票数 0

我试图从python文档中设置计时器的值,我的问题是,在获取数据之后,如何插入每个区域的时间?

代码语言:javascript
复制
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请求获得的值传递给数组。

请帮帮忙。

EN

回答 1

Stack Overflow用户

发布于 2022-08-01 15:31:14

这在很大程度上取决于您正在获取的数据的结构方式。

这也取决于您到底想要实现什么,您希望数组中的值在任何时候都存在吗?

您希望保留此功能吗?重新加载页面或网站的各种页面(假设您正在创建某种网站)。

最简单的方法就是这样做,->

代码语言:javascript
复制
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)))})
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73194902

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档