Have a button

<button type="button" class="btn btn-default"></button> 

I transfer model with data in html

 func TakeToRepairTreatment(rnd render.Render){ bks := models.ModelTakeToRepairTreatment() rnd.HTML(200, "take_to_repair_treatment", bks) } 

In bks there is a field Lgotcat, how to substitute it in

 <button type="button" class="btn btn-default">Сюда</button> 

I fill the table without problems:

  {{ range $key, $value := . }} <tr> <td> <form action="edit" method="POST" > <button type="text" class="btn btn-default btn-md"> <input type="hidden" name="id" value="{{$value.Id}}"> <span class="glyphicon glyphicon-user" aria-hidden="true"></span> </button> </form> </td> <td>{{$value.Id}}</td> <td>{{$value.DateRecord}}</td> <td>{{$value.Fam}} {{$value.Name}} {{$value.Lastname}}</td> <td>{{$value.Datebirth}}</td> <td> <form action="print_queue" method="POST"> <button type="text" class="btn btn-default btn-md"> <input type="hidden" name="id" value="{{$value.Id}}"> <span class="glyphicon glyphicon-print" aria-hidden="true"></span> </button> </form> </td> {{end}} 

And how to display the values ​​of one field, not in a loop, I can not figure it out.

thank

    1 answer 1

    If bks is a structure with a field, then simply

     <button type="button" class="btn btn-default">{{.Lgotcat}}</button> 
    • The problem is that bks is an “array” and you cannot access the field with a simple .Lgotcat - Evgeny Gusev
    • @ Yevgeny Gusev Then what’s stopping you from doing the same in a loop? {{$value.Lgotcat}} ? Or whatever you want, I do not understand. - Ainar-G
    • Then the cycle will display all entries with preferential categories (which are also loaded into the table). I need to display one entry something like. Lgotcat [1] - Evgeny Gusev
    • one
      @ EvgenyGusev Then why do not you use the index function ? - Ainar-G