1

I am retrieving data from one component in react that is being passed into another component as a 2d array.

console.log(this.props.cheatsheet) Results in [object Object],[object Object]

console.log(JSON.stringify(this.props.dashboards)); shows me the arrays values below

[  
   {  
      "name":"Test",
      "description":"TEest",
      "filter":[  
         "201158",
         "200461",
         "201345"
      ],
      "KPIs":[  

      ]
   },
   {  
      "name":"Asset Owner Dashboard",
      "description":"Description for Asset Owner Dashboard",
      "filter":[  
         "201732",
         "222323",
         323244
      ],
      "KPIs":[  
         {  
            "name":"Asset",
            "charts":[  
               {  
                  "name":"Details"
               }
            ]
         },
         {  
            "name":"Incidents",
            "charts":[  
               {  
                  "name":"Count by AssignmentGroup"
               },
               {  
                  "name":"COE Open Tickets"
               },
               {  
                  "name":"NEW IM in Last 48hrs"
               }
            ]
         },
         {  
            "name":"Problem Tickets",
            "charts":[  
               {  
                  "name":"Count by Status"
               },
               {  
                  "name":"Open PMR"
               },
               {  
                  "name":"Details"
               }
            ]
         }
      ]
   }
]

what is the best way for me to map the filter array from test and Asset Owner Dashboard

1
  • You can use lodashJs filter method. Commented Jan 6, 2017 at 13:44

1 Answer 1

1

You can make use of nested maps to render you data. just like the below example

class App extends React.Component {
   render(){
      var arr = [  
   {  
      "name":"Test",
      "description":"TEest",
      "filter":[  
         "201158",
         "200461",
         "201345"
      ],
      "KPIs":[  

      ]
   },
   {  
      "name":"Asset Owner Dashboard",
      "description":"Description for Asset Owner Dashboard",
      "filter":[  
         "201732",
         "222323",
         323244
      ],
      "KPIs":[  
         {  
            "name":"Asset",
            "charts":[  
               {  
                  "name":"Details"
               }
            ]
         },
         {  
            "name":"Incidents",
            "charts":[  
               {  
                  "name":"Count by AssignmentGroup"
               },
               {  
                  "name":"COE Open Tickets"
               },
               {  
                  "name":"NEW IM in Last 48hrs"
               }
            ]
         },
         {  
            "name":"Problem Tickets",
            "charts":[  
               {  
                  "name":"Count by Status"
               },
               {  
                  "name":"Open PMR"
               },
               {  
                  "name":"Details"
               }
            ]
         }
      ]
   }
]
      
      return (
        <tbody>
           {arr.map(function(item){
               return (
                  <tr>
                     {item.filter.map(function(val){
                       return <td>{val}</td>
                       
                      })}
                  </tr>
               )
           })} 
        </tbody>
      )
   }
}

ReactDOM.render(<App/>, document.getElementById('app'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.8/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.8/react-dom.min.js"></script>
<div id="app"></div>

Sign up to request clarification or add additional context in comments.

1 Comment

Glad to have helped :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.