1

我正在尝试通过 iris golang web 框架中的一段结构,如下所示。

type prodcont struct{
List []Post
}


type Post struct{
    Id int
    Title string
    Slug string
    ShortDescription string
    Content string
}

var Posts = []Post{
    Post{content ommitted}
 }   


 //GET categories
func IndexPost(c *iris.Context){
    c.Render("admin/post/index.html", prodcont{Posts}, iris.RenderOptions{"gzip": true})
}


    <table class="table table-striped table-bordered">
        <thead>
            <thead>
                table head...
            </thead>
        </thead>
        <tbody>
   {{run range here}}
    <tr>
        <td>{{post.Id}}</td>
        <td>{{post.Title}}</td>
        <td>{{post.Slug}}</td>
        <td>{{post.Shortdescription}}</td>
        <td>{{post.Content}}</td>
    </tr>
    {{end}}
        </tbody>
    </table>

我试过了{{range .}}{{for _posts := range Posts}}.etc 哪个没用?

这是我得到的错误

template: template/admin_template.html:61:7: executing "template/admin_template.html" at <yield>: error calling yield: html/template: "admin/post/index.html" is an incomplete template

在 Go Iris 框架中,我如何能够有效地通过上面所见的结构切片?谢谢

4

1 回答 1

2

for post :=通过在以下示例中删除来修复问题{{range .List}}

 {{range .List}}
<tr>
    <td><input class="checkbox" type="checkbox" name="category" value=""></td>
    <td>{{.Id}}</td>
    <td>{{.Title}}</td>
    <td>{{.Slug}}</td>

</tr>
{{end}}
于 2016-09-26T18:35:48.427 回答