Answer the question
In order to leave comments, you need to log in
How to display in GO in template struct?
For some reason, {{.time}} crashes with an error
executing "index.html" at <.time>: time is an unexported field of struct type main.tb
type tb struct {
time string
booking bool
}
type Room struct {
Name string
Bookings []tb
}
var rooms = make(map[int]Room)
var TIME_CONST = []tb{
tb{"8:00",false },tb{"8:30",false },
tb{"9:00",false },tb{"9:30",false },}
func addRoom(name string) {
rooms[cns] = Room{ name,TIME_CONST}
cns++
}
<ul class="list-group">
{{range $key, $value := .}}
<li class="list-group-item">
<a href="/bookingDetails" > {{$key}} {{.Name}} </a>
{{range .Bookings}}
{{.time}}
{{ end }}
</li>
{{ end }}
</ul>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question