javascript - Display first post from query -


from query:

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

i'm trying display latest post in jade template, this:

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

but empty, can explain how can this?

many thanks

edit dump mongodb, not sure how else show whats in data:

/** 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" }); 

this how loop through data in view:

each post in locals.data.posts             ul             each item in post                 li                     a(href='/blog/post/' + item.slug) #{item.title}  


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -