显示查询中的第一个帖子

时间:2015-06-01 07:49:10

标签: javascript pug keystonejs

来自此查询:

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);
    });

我试图在我的玉石模板中显示最新帖子,如下所示:

#{locals.data.posts.post[0].title}

但它是空的,任何人都可以解释我怎么做到这一点?

非常感谢

来自我的mongoDB的EDIT转储,不知道如何在我的数据中显示什么:

/** 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} 

0 个答案:

没有答案