GIN Web 框架 (DataTable jquery 插件:无法设置未定义的属性'_DT_CellIndex')



我得到了以下GinWeb框架代码,其中我使用了dataTablejQuery插件。我的问题与{{.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},则没有任何错误,但如果我放置{{.SliceDisposition},则会得到以下错误:

不幸的是,我收到以下错误

jquery.min.js:2 Uncaught TypeError: Cannot set property '_DT_CellIndex' of undefined
at Za (jquery.dataTables.min.js:41)
at ea (jquery.dataTables.min.js:32)
at HTMLTableRowElement.<anonymous> (jquery.dataTables.min.js:33)
at jquery.min.js:2
at Function.map (jquery.min.js:2)
at S.fn.init.map (jquery.min.js:2)
at Ga (jquery.dataTables.min.js:33)
at e (jquery.dataTables.min.js:109)
at HTMLTableElement.<anonymous> (jquery.dataTables.min.js:110)
at Function.each (jquery.min.js:2)

任何帮助对我来说都很方便!

问候

问题是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中插入一个切片字符串
然后请将其作为模板交付。

最新更新