一切我可以找到一個撕心裂肺頁面貓鼬結果說做這樣的:如何從find方法返回Mongoose結果?
users.find({}, function(err, docs){
res.render('profile/profile', {
users: docs
});
});
我怎麼能返回結果從查詢,更喜歡這個?
var a_users = users.find({}); //non-working example
這樣我就可以得到多個結果在頁面上發佈?
喜歡:
/* non working example */
var a_users = users.find({});
var a_articles = articles.find({});
res.render('profile/profile', {
users: a_users
, articles: a_articles
});
可以這樣做?
當[ES7滾動](http://jakearchibald.com/2014/es7-async-functions/)時,你的夢想就會實現。 – royhowie 2015-06-13 04:23:15
你應該簽出[deasync](https://www.npmjs.com/package/deasync),所以函數看起來像是同步執行的。 – 2015-07-25 21:24:01
爲更好地理解這個問題和它的解決方案參考https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – devprashant 2017-06-02 16:49:10