【发布时间】:2011-04-23 08:59:40
【问题描述】:
假设我有这样的数据结构:
type Foo struct {
Bar []struct {
FooBar string
}
}
我填充它使得 Bar 有 3 个元素。现在,使用template 库,我如何访问该切片中的第三个元素FooBar?我尝试了以下方法但没有成功:
{Foo.Bar[2].FooBar}
{Foo.Bar.2.FooBar}
现在,我知道我可以使用{.repeated section Foo.Bar} {FooBar} {.end},但这为我提供了 每个 元素的 foobar 值,而不仅仅是一个特定的元素。我用谷歌搜索并在 irc 上询问无济于事......
【问题讨论】: