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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

為什么傳遞的變量沒(méi)有在 html/template 中呈現(xiàn)?

為什么傳遞的變量沒(méi)有在 html/template 中呈現(xiàn)?

Go
阿波羅的戰(zhàn)車(chē) 2023-08-07 14:58:19
我不明白為什么傳遞的變量沒(méi)有用 html/template 渲染這是瀏覽器中呈現(xiàn)的內(nèi)容:這是所有傳遞的變量: [0xc0000a8ec0 0xc0000a8f80 0xc0000a9040 0xc0000a9100]城市 人口 州 國(guó)家 首都這是日志:$ go run main.go2019/11/27 11:00:39 **** => &city has &main.City{Name:"Washington D.C.", State:"", Country:"USA", Capital:false, Population:680000} before appending to cities ****2019/11/27 11:00:39 **** => &city has &main.City{Name:"Los Angeles", State:"CA", Country:"USA", Capital:false, Population:3900000} before appending to cities ****2019/11/27 11:00:39 **** => &city has &main.City{Name:"San Francisco", State:"CA", Country:"USA", Capital:false, Population:860000} before appending to cities ****2019/11/27 11:00:39 **** => &city has &main.City{Name:"Tokyo", State:"", Country:"Japan", Capital:true, Population:9000000} before appending to cities ******** => cities outside {} has 4這是處理函數(shù):func indexHandler(w http.ResponseWriter, r *http.Request) {    projectID := "XXXXXXXXXXXXXX"    ctx := context.Background()    client, _ := firestore.NewClient(ctx, projectID)    query := client.Collection("cities").Documents(ctx)    defer query.Stop()    cities := make([]*City, 0)    for {        doc, err := query.Next()        if err == iterator.Done {            break        }        c := doc.Data()        // is there an easier way to populate the city struct        city := City{            Name:       c["name"].(string),            Country:    c["country"].(string),            Population: c["population"].(int64),        }        // This is my ugly solution to dealing with nil value from Firestore        _, ok := c["capital"]        if ok {            city.Capital = c["capital"].(bool)        }        state, ok := c["state"].(string)        if ok {            city.State = state        }        log.Printf("**** => &city has %#v before appending to cities ****", &city)        cities = append(cities, &city)    }    fmt.Printf("**** => cities outside {} has %d", len(cities))    indexTemplate.Execute(w, cities)    }
查看完整描述

1 回答

?
紫衣仙女

TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊

永遠(yuǎn)不要遺漏錯(cuò)誤,檢查indexTemplate.Execute(w, cities)返回的內(nèi)容。它可能揭示了原因:

cities作為數(shù)據(jù)傳遞,這是一個(gè)切片。沒(méi)有cities它的領(lǐng)域或方法。傳遞的數(shù)據(jù)成為點(diǎn),因此您必須在點(diǎn)上進(jìn)行范圍。

代替:

{{ range .cities }}

使用:

{{ range . }}


查看完整回答
反對(duì) 回復(fù) 2023-08-07
  • 1 回答
  • 0 關(guān)注
  • 126 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)