Template passes non-nil object becomes nil in frontend

163 views Asked by At

basically I have an object wanted to pass to the frontend. I logged it in the backend and it was not null, but in the frontend when I alerted it, it becomes null.

...
presentation := &presentationStruct {
  Object: object,
}
log.Errorf("%v", object) // not null
template.Execute(writer, presentation)
...

// but it becomes null here
alert({{.Object}})

The object is a type of

map[string]map[string]struct {
  []float32
  map[int][]struct {
    string
    float32
  }
}

Is it because the type is too complicated?

1

There are 1 answers

8
Jiang YD On

No, it does not matter that the type is complicated. Template is not for passing struct from backend in Go to frontend in JavaScript. It is just do string replacement, replace strings in template with variables in Go and send final string.