第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 go text/template 使用中使用 .Key

如何在 go text/template 使用中使用 .Key

Go
慕森王 2021-08-16 16:11:06
我不明白http://golang.org/pkg/text/template/ 中的文檔段落- The name of a key of the data, which must be a map, preceded  by a period, such as    .Key  The result is the map element value indexed by the key.  Key invocations may be chained and combined with fields to any  depth:    .Field1.Key1.Field2.Key2  Although the key must be an alphanumeric identifier, unlike with  field names they do not need to start with an upper case letter.  Keys can also be evaluated on variables, including chaining:    $x.key1.key2這是我的測試代碼,但失敗了。代碼:http : //play.golang.org/p/lbLJ4yoL2T。var season = map[int]string{1: "spring", 2: "summer",                      3: "autumn", 4: "winter"}                                  func main() {                                                              const greeting = `Welcome, {{.Key}}`                               t := template.Must(template.New("greet").Parse(greeting))          err := t.Execute(os.Stdout, season)                                if err != nil {                                                            fmt.Println(err)                                           }                                                          }                                                                  輸出Welcome, template: greet:1:11: executing "greet" at <.Key>: can't evaluate field Key in type map[int]string
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 266 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號