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

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

Golang,追加只留下最后一個(gè)元素

Golang,追加只留下最后一個(gè)元素

Go
UYOU 2021-09-10 15:04:41
這是示例代碼:package mainimport (    "fmt")type Product struct {    Id       int64    Title    string    AttrVals []string}type ProductAttrValView struct {    Product    Attr string}type ProductAttrVal struct {    Attr    string    Product int64    Value   string}func main() {    p := Product{Id: 1, Title: "test", AttrVals: []string{}}    var prod *Product    prodViews := []ProductAttrValView{        ProductAttrValView{ Product: p, Attr: "text1" },        ProductAttrValView{ Product: p, Attr: "text2" },        ProductAttrValView{ Product: p, Attr: "text3" },        ProductAttrValView{ Product: p, Attr: "text4" },    }    // collapse join View to Product with Attrs    for _, pview := range prodViews {        if prod == nil {            prod = &pview.Product            prod.AttrVals = make([]string, 0, len(prodViews))        }        if pview.Attr != "" {            fmt.Printf("appending '%s' to %p\n", pview.Attr, prod) // output for debug            prod.AttrVals = append(prod.AttrVals, pview.Attr)        }    }    fmt.Printf("%+v\n", prod) // output for debug}http://play.golang.org/p/949w5tYjcH這里我有一些從ProductAttrValView結(jié)構(gòu)體中的DB 返回的數(shù)據(jù),并希望將其放入Product結(jié)構(gòu)體并填充Product.AttrVals它打?。?amp;{Id:1 Title:test AttrVals:[text4]}雖然我期待這個(gè):&{Id:1 Title:test AttrVals:[text1 text2 text3 text4]}因此,應(yīng)該附加所有文本,但出于某種原因,只有最后一個(gè)元素保留在Attrs切片中。
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 272 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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