在mongojs,當你這樣做:調用函數以外的路徑
var birds = db.birds.find(searchTerm, callback);
...你如何參數傳遞給回調?我試過綁定,如:
birds = db.birds.find(searchTerm, app.get('getBirds').bind(res));
......但無濟於事。只是fyi我試圖傳遞GET路由的響應對象,以便回調可以使用res.send(結果)呈現。
另一個選項是設置app.set('res':res);並從回調中調用app.get('res') - 我不確定這是個好主意。它的工作原理,但它不太遵守事件循環模型 - 我認爲回到應用程序的請求可能是昂貴的?任何幫助將被感激地接受。 :)
是的,它就是這樣完成的: birds = db.birds.find(searchTerm ,function(err,birds){app.get('renderResults')(err,birds,res)}); 做得好的傢伙。 :) – user1775718