如何重命名数组中的对象?
我正在尝试使用此 API,但是我想通过 strMeasure & 使用 for 循环或映射。字符串成分。目前,这些附件的数量少于 20 个。所以我想我需要先使用 for 循环创建一个数组,然后再实现它?让我知道你的想法..
const [recipeData, setRecipeData] = useState([]);
const ingredientList = recipeData.map((allData) => {
const arr = [];
for (let i = 1; i <= 20; i++) {
arr.push(allData[`strMeasure${i}`] + " " + allData[`strIngredient${i}`]);
}
return arr;
});
但随后不知道如何将其注入我的组件中。
干杯!
I am trying to use this API however, I want to use a for loop or map through the strMeasure & strIngredient. Currently those have numbers less than 20 attached. So I am thinking I need to make an array first using a for loop and then implement it? Let me know your thoughts..
const [recipeData, setRecipeData] = useState([]);
const ingredientList = recipeData.map((allData) => {
const arr = [];
for (let i = 1; i <= 20; i++) {
arr.push(allData[`strMeasure${i}`] + " " + allData[`strIngredient${i}`]);
}
return arr;
});
But then do not know how to inject this in my component.
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议不要将它们连接到字符串,而是将它们存储为对象中的键值对。这样可以更轻松地访问 UI 中的值。
转换数据后,您可以轻松地将其传递给您的组件
Instead of jointing them to a string, I would suggest storing them as key, value pairs within an object. This way it is easier to access the values in your UI.
After you transformed your data, you can pass it easily to your component