簡體   English   中英

React 將標簽添加到 Object.keys 映射中的嵌套數組對象

[英]React add label to nested array object in Object.keys map

我有一個 React 組件,它通過 axios.get 調用提取 JSON 數據,然后我使用以下函數映射一個嵌入式對象:

axios.get('MasterData.json').then(response => {
       const fullTree = response.data.graph.tree;
       const resultTree = Object.keys(fullTree).map(key => ({
          ...fullTree[key],
         id: key
    }));

這會產生以下結果:

{5bd356cc-5ee6-49a0-ab68-65cbf0209105: Array(6), id: "5bd356cc-5ee6-49a0- ab68-65cbf0209105"}

這很好,但我需要在上面輸出的整個嵌套數組 (Array(6)) 中添加一個“端口:”標簽,以便我可以映射它。感謝任何幫助。

axios.get('MasterData.json').then(response => {
   const fullTree = response.data.graph.tree;  
   console.log(fullTree) // you must check this fist
   const resultTree = Object.keys(fullTree).map(key => 
     new Port({  // create some function to generate get port as you want
        port : fullTree[key],
        id: key
     )
});

對於創建功能,也許在下面我可以解釋更多:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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