![](/img/trans.png)
[英]React.JS & JSX - Map of components from list of objects only using value from first object in list
[英]I am trying to map IDs from inside a list of objects into a new list using React js
我想通過從現有對象列表中獲取 ID 並將其復制到可在整個組件中訪問的新列表來從現有列表創建一個新列表。
此現有列表作為 BE API 響應的一部分返回
const key = [];
await RequestPortInService.fetchCurrentServices().then(response => {
response.currentServiceList.map(key => (
key = response.currentServiceList.serviceId
));
alert(key);
})
您在對象 response.currentServiceList.map 中的鍵值將在鍵上,因此請嘗試使用
var newSerivceIds = {};
await RequestPortInService.fetchCurrentServices().then(response => {
newSerivceIds= response.currentServiceList.map(key =>
{return key.serviceId});
})
alert(newSerivceIds)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.