Nested object data

Nested object data

El_MatellaEl_Matella Posts: 12Questions: 6Answers: 0

Hi,

I am having some questions about manipulation of Json data into a table. My Json is like this one:

[
    {
        id: 1
        name: 'My Product',
        language: [
            {
                'description': 'My description',
                'language': {
                    name: 'fr'
                }
            },
            {
                'description': 'My alternative description',
                'language': {
                    name: 'en'
                }
            }
        ]
    },
    {
        id: 2
        name: 'My Second Product',
        language: [
            {
                'description': 'My description',
                'language': {
                    name: 'fr'
                }
            }
        ]
    },
]

And my table is like:

<table id="Table">
    <thead>
        <th>ID</th>
        <th>name</th>
        <th>description</th>
    </thead>
    <tbody>
    </tbody>
</table>

And I want to display inside the description field, the description in a certain language, for example were language.name is 'fr'.
As you can see, every product object has a language array, and a language item contains a description, and language information. So for example, for the first product, I should have in my table the following:

<table id="Table">
    <thead>
        <th>ID</th>
        <th>name</th>
        <th>description</th>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>My Product</td>
            <td>My Description</td>
        </tr>
        <tr>
            <td>2</td>
            <td>My Second Product</td>
            <td>My description</td>
        </tr>
    </tbody>
</table>

I looked at this example: https://www.datatables.net/examples/ajax/objects_subarrays.html

But I can't find how I could make conditions on the content of that... Maybe I should use createdRow instead but I am not quite sure...

If someone could light me up, I would appreciate it a lot!

Thanks in advance :)

Answers

This discussion has been closed.