node.js - Use Ajax to load posts in Keystone -
i want able load earlier pages current page once have reached bottom of document. want able reusable jade partial.. or similar that.
this need connected keystone.js supplying data jade partial
i create ajax call so:
// load more posts var currentpage = 1; function addnextpage(currentpage){ currentpage++; var parameters = { "currentpage": currentpage }; $.get( "/addnextpage", parameters, function(data) { $.each(data, function (key) { $(".news").append(data); }); }); } var scrollnews = _.throttle(function(e) { if($(window).scrolltop() + $(window).height() > $(document).height() - 300) { addnextpage(currentpage); } }, 500); window.addeventlistener("scroll", scrollnews, false);
how keystonejs render , respond partial specific paginated page?
you add respective route page
app.get("/addnextpage",function(req, res, next){ var view = new keystone.view(req, res), locals = res.locals; // renit locals locals.section = 'news'; locals.filters = { category: req.params.category }; locals.data = { posts: [], categories: [] }; var q = keystone.list('post').paginate({ page: req.query.currentpage || 1, perpage: 3 }) .where('state', 'published') .sort('-publisheddate') .populate('author categories'); q.exec( function(err, results) { if (err) { throw err; } else { console.log('recieved posts page'); locals.data.posts = results; jade.renderfile('templates/partials/newspost.jade', locals, function(err, results) { if (err) { throw err; } else { console.log('rendered jade'); globalres(results) } }); } }); function globalres(results){ res.send(results); } });
Comments
Post a Comment