简体   繁体   English

React 将标签添加到 Object.keys 映射中的嵌套数组对象

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

I have a React component which is pulling JSON data via an axios.get call and then I am mapping an embedded object using the following function:我有一个 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
    }));

This produces the following:这会产生以下结果:

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

which is great, but I need to add a label of "ports: to the entire nested array (Array(6)) that is being output above so that I can map it. Any help is appreciated.这很好,但我需要在上面输出的整个嵌套数组 (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
     )
});

for create function maybe on bellow me can explain more :)对于创建功能,也许在下面我可以解释更多:)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM