2016-09-26 4 views
0

私は、以下のように、golang Webフレームワークのアイリスで構造体のスライスを範囲指定しようとしています。Iris Goフレームワークで構造体のスライスを範囲指定する方法は?

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 

どのように私は行くアイリスの枠組みの中で効果的に上で見たよう構造体のスライスまでの範囲することができるだろう取得エラーですか? おかげ

+2

と、次の例にfor post :=を除去することによって、問題を修正しましたか – jcbwlkr

+1

'prodcont'の定義を表示します。また、 '{{post:= range .Posts}}'を試してみましたか? –

+0

こんにちは、ありがとう、私はエラーメッセージと 'prodcont'構造体を追加しました –

答えて

1

は、あなたがどのようなエラーメッセージを得るのですか?{{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}} 
関連する問題