samedi 25 mai 2019

Show a table from a slice with my struct Golang

I want to show a table that each row contains my struct data.

Here is my struct:

type My_Struct struct {
FIRST_FIELD       string
SECOND_FIELD      string
THIED_FIELD       string
}

Here is my html code:

<table id="t01">
<tr>
    <th>FIRST FIELD</th>
    <th>SECOND FIELD</th>
    <th>THIRD FIELD</th>
</tr>
<tr>
    <td>FIRST_OBJ_HERE_SHOULD_BE_THE_FIRST_FIELD</td>
    <td>FIRST_OBJ_HERE_SHOULD_BE_THE_SECOND_FIELD</td>
    <td>FIRST_OBJ_HERE_SHOULD_BE_THE_THIRD_FIELD</td>
</tr>

<tr>
    <td>SECOND_OBJ_HERE_SHOULD_BE_THE_FIRST_FIELD</td>
    <td>SECOND_OBJ_HERE_SHOULD_BE_THE_SECOND_FIELD</td>
    <td>SECOND_OBJ_HERE_SHOULD_BE_THE_THIRD_FIELD</td>
</tr>

</table>

As you see, I want to pass a slice with my struct (each one contains 3 files) to this html code, and I want the the whole slice will be set in this table - each row contains one struct data.

How can I achieve this?

Thank you!




Aucun commentaire:

Enregistrer un commentaire