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

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

GIN Web 框架

GIN Web 框架

Go
精慕HU 2022-07-11 16:50:17
我有以下使用 dataTable jQuery 插件的 Gin Web 框架代碼。我的問題與 {{ .SliceDescription }} 有關(guān),之后我在我的模型中定義它:<table id="example" class="table table-striped table-bordered" style="width:100%">        <thead>            <tr>                <th>Τ?τλο?</th>                <th>Περιγραφ?</th>                <th>Επισκ?πηση</th>                <th>Ενημ?ρωση</th>                <th>Διαγραφ?</th>                        </tr>        </thead>        <tbody>                        {{range .todo}}            <tr>                <td>{{ .Title }}</td>                **<td>{{ .SliceDescription }}</td>**                 <td><a href="/tasks/todo/{{ .ID }}" class="btn btn-success btn-sm viewlink" role="button" data-toggle="modal" data-target="#viewModal"><i class="fas fa-eye"></i></a>                </td>                <td><a href="/tasks/todo/{{ .ID }}" class="btn btn-warning btn-sm" role="button"><i class="fas fa-edit"></i></a></td>                <td><a href="/tasks/todo/{{ .ID }}" class="btn btn-danger btn-sm  deletelink" role="button"><i class="fas fa-trash-alt"></i></a></td>                                      </tr>            {{end}}        </tbody>        <tfoot>            <tr>                <th>Τ?τλο?</th>                <th>Περιγραφ?</th>                <th>Επισκ?πηση</th>                <th>Ενημ?ρωση</th>                <th>Διαγραφ?</th>            </tr>        </tfoot>    </table>使用 jquery 代碼: $(document).ready(function() {            $('#example').DataTable();            });我通過 GIN WEB FRAMEWORK 中的 GORM 定義我的數(shù)據(jù)庫(kù)模型:type Todo struct {    ID uint             `gorm:"primary_key;AUTO_INCREMENT" `    Title string        `gorm:"not null" json:"title" `    Description string  `gorm:"not null" json:"description" `}func (b Todo) SliceDescription() string {    return string(b.Description[:45]) }func (b *Todo) TableName() string {    return "todo"} 如果我放置 {{.Description}} 而不是 {{ .SliceDescription }} 則沒有任何錯(cuò)誤,但如果我放置 {{ .SliceDescription }} 我會(huì)得到以下錯(cuò)誤
查看完整描述

1 回答

?
繁花如伊

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

問題是 SliceDescription 是一個(gè)函數(shù)。

將 SliceDescription 添加到 Todo 結(jié)構(gòu)中,如下所示。


type Todo struct {

    ID uint             `gorm:"primary_key;AUTO_INCREMENT" `

    Title string        `gorm:"not null" json:"title" `

    Description string  `gorm:"not null" json:"description" `

    SliceDescription string

}

請(qǐng)?jiān)?Todo 的 SliceDescription 中插入一個(gè)切片字符串。

那么請(qǐng)將其作為模板提供。


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

添加回答

舉報(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)