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

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

Golang 無法在視圖中顯示檢索到的數(shù)據(jù)

Golang 無法在視圖中顯示檢索到的數(shù)據(jù)

Go
富國滬深 2021-07-03 14:00:02
希望這是我與指針有關(guān)的最后一個問題:我正在調(diào)用存儲庫方法來獲取一部分健身房課程。我在這樣的視圖中顯示它們:    {{ range .}}            {{.VideoPath}} << Correct            <br>            {{.Instructor.Email}} << Blank            <br>            {{.ClassType.ClassTypeCode}} << Blank                   {{end}}   教師和類類型字段作為空結(jié)構(gòu)出現(xiàn),但在 ClassRepository 中我做了一些 Printlns 并打印了正確的數(shù)據(jù)。某處存在指針問題或其他問題。我做錯了什么?這是存儲庫:package repositories    type ClassRepository struct {    Gorp gorp.SqlExecutor}func (c ClassRepository) ClassesForLastNDays(days int) []entities.Class {    var classes []entities.Class    // Gets the classes - omitted for brevity    c.populateClassRelationships(classes)    return classes}func (c ClassRepository) populateClassRelationships(classes []entities.Class) {    for i := range classes {        class := classes[i]        // ClassType        obj, err := c.Gorp.Get(entities.ClassType{}, class.ClassTypeCode)        if err != nil {            panic(err)        }        class.ClassType = *obj.(*entities.ClassType)        fmt.Println(class.ClassType) << Returns correct data        // Instructor and Equipment        Same for instructor and Equipment    }}更新:經(jīng)過大量的 printlns,我可以確認問題出在 populateClassRelationships 之后,填充的值都丟失了。func (c ClassRepository) ClassesForLastNDays(days int) []entities.Class {        var classes []entities.Class        // Gets the classes - omitted for brevity        c.populateClassRelationships(classes) <<<< In the method,Println has values        return classes <<<< Values have been lost    }
查看完整描述

1 回答

?
精慕HU

TA貢獻1845條經(jīng)驗 獲得超8個贊

我相信問題在于您的函數(shù)populateClassRelationships沒有修改原始數(shù)據(jù)結(jié)構(gòu),如以下最終輸出的代碼所示:


[1]

[]

不工作


func myFunc(data []int) {

    data = append(data, 1)

    fmt.Println(data)

}


func main() {

    d := []int { }

    myFunc(d)

    fmt.Println(d)

}

引入?yún)?shù)作為指針可以修改原始數(shù)據(jù)


func myFuncNew(data *[]int) {

        *data = append(*data, 1)

    fmt.Println(*data)

}


查看完整回答
反對 回復(fù) 2021-07-19
  • 1 回答
  • 0 關(guān)注
  • 213 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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