范围内的范围golang模板

range within range golang template

如何在 Go 模板中访问范围内的范围?

模板:

{{range .Resume.Skills}}    
    {{.Name}}
    {{.Level}}
    {{range $item, $key := .Keywords}}
            {{$key}}
            {{$item}}
    {{end}}
{{end}}

结构:

type SkillsInfo struct {
    Name     string
    Level    string
    Keywords []KeywordsInfo
}

type KeywordsInfo struct {
    Keyword string
}

我看到的结果是 {}。如何访问模板中的嵌套对象?

---更新--:

type ResumeJson struct {
    Basics       BasicsInfo
    Work         []WorkInfo
    Volunteer    []VolunteerInfo
    Education    []EducationInfo
    Awards       []AwardsInfo
    Publications []PublicationsInfo
    Skills       []SkillsInfo
    Languages    []LaunguagesInfo
    Interests    []InterestsInfo
    References   []ReferencesInfo
}

现在看到的结果:

Web 开发大师 {} 0 {} 1 {} 2

ans JSON 我解析:

 "skills": [{
    "name": "Web Development",
    "level": "Master",
    "keywords": [
         "CSS", 
         "HTML",
      "Javascript"
    ]
  }],

关键字在 JSON 中表示为字符串数组。更改 Go 类型以匹配 JSON:

type SkillsInfo struct {
  Name     string
  Level    string
  Keywords []string
}

并使用此模板:

{{range .Resume.Skills}}    
  {{.Name}}
  {{.Level}}
  {{range .Keywords}}
     {{.}}
  {{end}}
{{end}}

playground example