简体   繁体   English

我尝试使用 .map function 但它对我的代码不起作用

[英]I tried to use the .map function but it didn't work on my code

async function getCategoryIds ()
{
    let response = axios.get( `${BASE_API_URL}categories?count=100` );
    let catIds = response.data.map( c => c.id );
    return _.samplesize( catIds, NUM_CATEGORIES )  
};

This is my code I tried to change the data in [] but it still don't work这是我的代码,我试图更改 [] 中的数据,但它仍然不起作用

The main issue here is you have not used await in your code.这里的主要问题是您没有在代码中使用 await 。 adding await like the following should solve your problem -像下面这样添加 await 应该可以解决您的问题 -

let response = await axios.get( `${BASE_API_URL}categories?count=100` );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在PHP代码中向可编辑按钮添加可折叠表单? 我尝试了一些东西,但是没有用 - How to add collapsible form to edit-button inside PHP code? I tried something, but didn't work 我的切换器不工作。 我试过将 js cdn 放在顶部和底部,但没有用 - My toggler is not working. I have tried placing js cdn in top and bottom both but didn't work React js:map 函数在函数内部不起作用 - react js : the map function didn't work inside a function 我试图在浏览器中制作一个画家,但后来它制作了一个“橡皮擦”,但它不起作用,因为它不会改变颜色 - I tried to make a painter in browser, but then it went to making an 'eraser' it didn't work because it doesn't change the color 我试图拖放一个元素。 为什么我的代码不能正常工作? - I have tried to drag and drop an element. Why won't my code work properly? 我尝试使用 fisher-yates shuffle 字符串,但没有奏效 - I tried using a fisher-yates shuffle for strings, but it didn't work 为什么我的onclick功能没有起作用 - why my onclick function didn't work in react 我的虚拟键盘中的删除功能在javascript中不起作用 - delete function in my virtual keyboard didn't work in javascript 使用 ref 不起作用 - counterElement.getElementById 不是函数 - use ref didn't work - counterElement.getElementById is not a function onmouseover功能不起作用 - onmouseover function didn't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM