How to pass multiple values from template to template?

前端 未结 2 566
误落风尘
误落风尘 2021-01-19 03:09

My City struct is like this:

type City struct {
    ID      int
    Name    string
    Regions []Region
}  

And Region

2条回答
  •  长情又很酷
    2021-01-19 03:12

    I guess CityWithSomeData is a slice, if so have a try like that:

    type viewModel struct {
        List   []City
    }
    

    then, in your template:

    {{range .List}}
            {{$city:=.Name}}
                {{range .Regions}}
                          {{$region:=.Name}}
                          {{template "data" .Shops $city $region}}
                {{end}}
    {{end}}
    

提交回复
热议问题