如果我在range语句中使用i18n语句,则会得到一个模板Execute err。但是我将i18n语句移到range语句之外。没关系。 错误消息是:
[D] [controller.go:283] template Execute err: template: userscontroller/get.tpl:16:244: executing "userscontroller/get.tpl" at <.Lang>: can't evaluate field Lang in type models.Account
[E] [server.go:2694] template: userscontroller/get.tpl:16:244: executing "userscontroller/get.tpl" at <.Lang>: can't evaluate field Lang in type models.Account
这是我的示例代码:
<ul class="w3-ul" id="UserList">
{{range $index, $user := .Users}}
<li class="w3-bar w3-hover-light-blue {{if eq $user.Role 1}}w3-pale-green{{end}} {{if eq $user.Role 2}}w3-pale-blue{{end}}{{if eq $user.Role 3}}w3-pale-red{{end}}" onclick="openProfile(this,{{$user.Uid}})">
<div class="w3-bar-item">
{{if eq $user.Role 1}}<span class="w3-large" style="color:green; font-weight: bold;">{{i18n .Lang ".users.administrator"}}</span>{{end}}{{if eq $user.Role 2}}<span class="w3-large" style="color:blue; font-weight: bold;">{{i18n .Lang ".users.user"}}</span>{{end}}{{if eq $user.Role 3}}<span class="w3-large" style="color:red; font-weight: bold;">{{i18n .Lang ".users.inactivated"}}</span>{{end}}<span class="w3-large Last">{{$user.Last}}</span> <span class="w3-large First">{{$user.First}}</span><br>
<span>{{i18n .Lang ".users.email"}}</span><span class="Email">{{$user.Email}}</span>
</div>
</li>
{{end}}
</ul>
有人遇到过类似的问题吗?怎么解决,谢谢。