我一直在做一个项目,在这方面我需要一些帮助:我在一个函数中有一个承诺,我需要返回"current“的值,这样我就可以在其他地方使用它。我从Firebase中检索数据,然后对结果进行混洗,只从结果中提取10个元素。
function retriveData() {
//declaration of variables ...
axios.get("Firebase link")
.then((response) => {
keyArray = Object.keys(response.data);
let k = shuffle(keyArray);
//shuffle is a function to shuffle the key results
for (var i = 0; i < 10; ++i) {
current[i] = response.data[k[i]];
}
});
return current;} //I want this variable to end up with the promise result in current我知道,这不是承诺的工作方式,但我需要一个解决方案来解决这个问题。谢谢!
https://stackoverflow.com/questions/51714983
复制相似问题