securedeveloper / react-data-export

Export dataset in react.
https://securedeveloper.github.io/react-data-export/
MIT License
179 stars 194 forks source link

Nested objects #73

Closed Akshara89 closed 6 years ago

Akshara89 commented 6 years ago

Json List for data [{ id: 1, name: "Bariatric Bed AH 1", img_thumb: [ 
"tn-arjo-huntleigh-bariatric-bed-2.jpg" ], asset_positions: [
{ id: 2, name: John } ]}, { id: 2, name: "Bariatric Bed AH 1", img_thumb: [ 
"tn-arjo-huntleigh-bariatric-bed-2.jpg" ], asset_positions: [
{ id: 2, Name: Peter } ]} } ]

I want to get asset_positions.name . I tried value= {(col) => col.asset_positions.name}. But still it is not working.

josealvaradoo commented 6 years ago

You could make an object without nested objects from your original data (on render method before return).

import data from "./data.json"

// Code

render() {
    let array = []
    data.map(item => {
        const obj = {
            id: item.id,
            name: item.name,
            img_thumb: item.img_thumb,
            asset_positions_1_id: ,
            asset_position_1_name: ,
            asset_position_2_id: ,
            asset_position_2_name: ,
        }
        array = array.concat(obj)
    })

    return ( .... )
}

You have to map each asset_position array. It is not a great solution, but is one. It would be ideal if the lib could use nested objects.

securedeveloper commented 6 years ago

@Akshara89 hopefully the snippet by @josealvaradoo will help you, if not please get back and we will help you. Thanks @josealvaradoo ❤️