我在这里阅读了类似的问题,但没有人帮助我解决问题。以下是html文件:
<div class="column col-10">
<select class="form-select" id="employeegend" name="emp_gend" value="{{.ItemSel.EmployeeGend}}">
<option {{if eq "M" .ItemSel.EmployeeGend}} selected {{end}} value="M">Maschio</option>
<option {{if eq "F" .ItemSel.EmployeeGend}} selected {{end}} value="F">Femmina</option>
<option {{if eq "S" .ItemSel.EmployeeGend}} selected {{end}} value="S">Altro</option>
</select>
</div>
结构:
Employee struct {
EmployeeId int `json:"emp_id"`
EmployeeName string `json:"emp_name"`
EmployeeLastN string `json:"emp_lastn"`
...
EmployeeGend string `json:"emp_gend"`
...
}
这是呈现页面在查看被截断的源时发生的事情:
<select class=form-select id=employeegend name=emp_gend value=M>
<option template: employees-edit:60:28: executing "main_content" at <.itemsel.employeegend>: can't evaluate field itemsel in type controllers.viewModel
为什么它在html select语句中而不是在以下html选项代码中评估.ItemSel.EmployeeGend?
看一下HTML属性标题here