Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go GIN Web框架(DataTable jquery插件:无法设置未定义的属性_Go_Datatables 1.10 - Fatal编程技术网

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

Go GIN Web框架(DataTable jquery插件:无法设置未定义的属性,go,datatables-1.10,Go,Datatables 1.10,我使用dataTable jQuery插件获得了以下Gin Web框架代码。我的问题与{{.SliceDescription}有关,之后我在模型中定义它: <table id="example" class="table table-striped table-bordered" style="width:100%"> <thead> <tr>

我使用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>
我通过GIN WEB框架中的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},则会得到以下错误:

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

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)
jquery.min.js:2未捕获类型错误:无法设置未定义的属性“\u DT\u CellIndex”
at Za(jquery.dataTables.min.js:41)
在ea(jquery.dataTables.min.js:32)
在HTMLTableRowElement。(jquery.dataTables.min.js:33)
在jquery.min.js:2
在Function.map(jquery.min.js:2)
位于S.fn.init.map(jquery.min.js:2)
在Ga(jquery.dataTables.min.js:33)
at e(jquery.dataTables.min.js:109)
在HTMLTableElement。(jquery.dataTables.min.js:110)
在Function.each(jquery.min.js:2)
任何帮助对我都很方便


关于

问题在于切片描述是一个函数。
将切片说明添加到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的切片描述中插入切片字符串。
然后请将其作为模板交付

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
}