Templates 具体范围示例
文本/模板包上的Go文档非常抽象,以至于我很难弄清楚如何在一片对象上进行实际范围。以下是我迄今为止的尝试(这对我来说没有任何结果):Templates 具体范围示例,templates,go,go-templates,Templates,Go,Go Templates,文本/模板包上的Go文档非常抽象,以至于我很难弄清楚如何在一片对象上进行实际范围。以下是我迄今为止的尝试(这对我来说没有任何结果): 范围是正确的。问题是上下文人员字段不是。模板包将忽略未报告的字段。将类型定义更改为: type Context struct { People []Person // <-- note that People starts with capital P. } 谢谢!现在,文本/模板包必须可以访问所有值,这是有道理的。 type Context str
范围是正确的。问题是上下文人员字段不是。模板包将忽略未报告的字段。将类型定义更改为:
type Context struct {
People []Person // <-- note that People starts with capital P.
}
谢谢!现在,文本/模板包必须可以访问所有值,这是有道理的。
type Context struct {
People []Person // <-- note that People starts with capital P.
}
{{range $i, $x := $.People}} Name={{$x.Name}} Senior={{$x.Senior}} {{end}}