亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

GIN Web 框架

GIN Web 框架

Go
精慕HU 2022-07-11 16:50:17
我有以下使用 dataTable jQuery 插件的 Gin Web 框架代碼。我的問題與 {{ .SliceDescription }} 有關,之后我在我的模型中定義它:<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 定義我的數據庫模型: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 }} 則沒有任何錯誤,但如果我放置 {{ .SliceDescription }} 我會得到以下錯誤
查看完整描述

1 回答

?
繁花如伊

TA貢獻2012條經驗 獲得超12個贊

問題是 SliceDescription 是一個函數。

將 SliceDescription 添加到 Todo 結構中,如下所示。


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

}

請在 Todo 的 SliceDescription 中插入一個切片字符串。

那么請將其作為模板提供。


查看完整回答
反對 回復 2022-07-11
  • 1 回答
  • 0 關注
  • 130 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號