node.js - mongoose and express - how to combine two functions into one output -
i'm trying make search form site, 2 separate inputs, 1 title keywords , other 1 body of post. don't know how pass these 2 variables (asd title , asdd body) function, thats app.js file :
app.get('/search', function(req, res) { postdb.findbytitle(asd, function(error, article) { res.render('search.jade', { locals: { title: article.title, articles:article } }); }); }); and here function finding (check bold parts):
postdb.prototype.findbytitle = function(**asd asdd**, callback) { this.getcollection(function(error, article_collection) { if( error ) callback(error) else { article_collection.find({**title: asd, body:asdd**}).toarray(function(error, results) { if( error ) callback(error) else callback(null, results) }); } }); };
pass couple of query string params url /search.
for example:
/search?title=asd&body=asdd; and use req object grab them , pass function:
app.get('/search', function(req, res) { var title = req.query.title ,body = req.query.body; postdb.findbytitle(title, body, function(error, article) { res.render('search.jade', { locals: { title: article.title, articles:article } }); }); });
Comments
Post a Comment