3 回答
TA贡献1863条经验 获得超2个赞
intID 是Key的内部属性,而不是struct,可以通过getter进行访问:
id := key.IntID()
GetAll返回[]*Key,您没有使用它:
_, err := q.GetAll(c, &blogposts)
解决此问题的一种方法是创建一个既包含帖子信息又包含关键信息的viewmodel结构(未经测试,但这是要点):
//... handler code ...
keys, err := q.GetAll(c, &blogposts)
if err != nil {
http.Error(w, "Problem fetching posts.", http.StatusInternalServerError)
return
}
models := make([]BlogPostVM, len(blogposts))
for i := 0; i < len(blogposts); i++ {
models[i].Id = keys[i].IntID()
models[i].Title = blogposts[i].Title
models[i].Content = blogposts[i].Content
}
//... render with mustache ...
}
type BlogPostVM struct {
Id int
Title string
Content string
}
- 3 回答
- 0 关注
- 250 浏览
添加回答
举报
