A
A
ajlhimik2019-06-17 20:40:06
Template Engines
ajlhimik, 2019-06-17 20:40:06

How to get highest range values ​​in golang template?

I have a form

<form method="POST" action="/saveLucr">
        {{ range .Proflist }}
        <b> <input name="name_lucru" type="text" value="{{ .NameProf }}" />&nbsp;&nbsp;</b>
        <b> <input name="orar_prof" type="text" value="{{ .OrarProf }}" /> </b>
       <label  id="addProfesie">add profesie</label>
        <table id="{{ .NameProf }}">
            <tbody>
                {{ range .PersList }}
                <tr name = "tr" id = "tr">
                    <td> Numele: <input name="name" type="text" value="{{ .NameLucr }}" /></td>
                    <td> Prenumele: <input name="surname" type="text" value="{{ .PrenumeLucr }}" /></td>
                    <td> Concediu I inceput: <input name="date_begin_concediu1" type="date" value="{{ .Begconc1 }}" /></td>
                    <td> Concediu I terminat: <input name="date_end_concediu1" type="date" value="{{ .Endconc1 }}" /></td>
                    <td> Concediu II inceput: <input name="date_begin_concediu2" type="date" value="{{ .Begconc2 }}" /></td>
                    <td> Concediu II terminat: <input name="date_end_concediu2" type="date" value="{{ .Endconc2 }}" /></td>
                    <td class="delete_button">  <label  id="del_tr1">Del</label> </td>
                </tr>
                {{ end }} 
             </tbody>
             
        </table>
        <P><label  id="addLucrator">Add_Lucrator</label></P>
        {{ end }}
        <input type="submit" value="GO!">
    </form>

it has 2 range cycles, there is json
{
    "Proflist" : [
        {"NameProf" : "inj",
        "OrarProf" : 8,
        "PersList" : [
            {
                "NameLucr" : "grisa",
                "PrenumeLucr" : "fas",
                "Begconc1": "5",
                "Endconc1" : "0",
                "Begconc2": "0",
                "Endconc2" : "0"
            },
            {
                "NameLucr" : "vasea",
                "PrenumeLucr" : "fas2",
                "Begconc1": "4",
                "Endconc1" : "2",
                "Begconc2": "4",
                "Endconc2" : "5"
            }
        ]},
        {"NameProf" : "ing2",
            "OrarProf" : 10,
            "PersList" : [
                {
                    "NameLucr" : "hhh",
                    "PrenumeLucr" : "dsa",
                    "Begconc1": "dsa",
                    "Endconc1" : "asd",
                    "Begconc2": "dsadfsadfasfas",
                    "Endconc2" : "kasdhfkjhasjkd"
                }
            ]}

      ]
}

it’s pushed in there and I need to create an id of the tr tag, I need it like this, like this , but it doesn’t work like that, as I understand that there is no NameProf in the PersList array, but how will it be addressed then? < <tr name = "tr" id = "tr"><tr name = "tr" id = "tr_{{ .NameProf }}">

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tyranron, 2019-06-18
@ajlhimik

Create iteration variables for outer loop:

<form method="POST" action="/saveLucr">
        {{ range $i, $p := .Proflist }}
        <b> <input name="name_lucru" type="text" value="{{ $p.NameProf }}" />&nbsp;&nbsp;</b>
        <b> <input name="orar_prof" type="text" value="{{ $p.OrarProf }}" /> </b>
       <label  id="addProfesie">add profesie</label>
        <table id="{{ $p.NameProf }}">
            <tbody>
                {{ range $p.PersList }}
                <tr name = "tr" id = "tr_{{ $p.NameProf }}">
                    <td> Numele: <input name="name" type="text" value="{{ .NameLucr }}" /></td>
                    ...
                </tr>
                {{ end }} 
             </tbody>
        </table>
        <P><label  id="addLucrator">Add_Lucrator</label></P>
        {{ end }}
        <input type="submit" value="GO!">
    </form>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question