このクエリから:
var q = keystone.list('Post').paginate({
page: req.query.page || 1,
perPage: 10,
maxPages: 10
})
.where('state', 'published')
.sort('-publishedDate')
.populate('author categories');
if (locals.data.category) {
q.where('categories').in([locals.data.category]);
}
q.exec(function(err, results) {
locals.data.posts = results;
next(err);
});
次のように、jade テンプレートに最新の投稿を表示しようとしています。
#{locals.data.posts.post[0].title}
しかし、それは空です。これを行う方法を誰か説明できますか?
どうもありがとう
私のmongoDBからの編集ダンプ、私のデータにあるものを他に表示する方法がわからない:
/** posts records **/
db.getCollection("posts").insert({
"__v": NumberInt(1),
"_id": ObjectId("553245bbdea6b152f4e96a9a"),
"author": ObjectId("552f90c2d877f67c1c70a0ea"),
"categories": [
ObjectId("5535fd895261330821d38109")
],
"content": {
"brief": "<p>TEst content</p>",
"extended": "<p>TEst contentTEst contentTEst contentTEst contentTEst content</p>"
},
"image": "",
"publishedDate": ISODate("2015-05-12T23:00:00.0Z"),
"slug": "tester",
"state": "published",
"title": "Tester"
});
db.getCollection("posts").insert({
"__v": NumberInt(0),
"_id": ObjectId("55604f7f5595f2581625a932"),
"categories": [
],
"content": {
"brief": "<p>dsfsdfsd</p>",
"extended": "<p>dfdsfsd</p>"
},
"image": "",
"slug": "sdffdsfs",
"state": "draft",
"title": "sdffdsfs"
});
これは、ビュー内のデータをループする方法です。
each post in locals.data.posts
ul
each item in post
li
a(href='/blog/post/' + item.slug) #{item.title}