簡體   English   中英

我正在嘗試使用 React js 將對象列表中的 ID 映射到新列表中

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM