1
我使用Nathan Broslawsky的簡單MVC結構。我有下面這些代碼。NodeJS在回調延遲時無法對瀏覽器進行response.write
ArticleProviderDBController.prototype.Show = function(data) {
//Init Model
var res = this.Response;
var model = this.getModel();
var view = this.getView("ArticleProviderDB");
model.findAll(function(error, article_collections){
if(error) console.log(error);
view.renderGH(res, data, article_collections); //this will actually call the renderGH function to serve a html file with data from DB but it is not working.
res.write('inside callback'); //this will not.
//res.end();
});
//console.log(_self.Response);
res.write('outside callback'); //this will be shown on my browser.
//res.end();
}
其實我試圖跟人做什麼用expressjs
app.get('/', function(req, res){
articleProvider.findAll(function(error,docs){
res.render('index.jade', {
locals: {
title: 'Blog',
articles:docs
}
});
})
});
但似乎它不工作。
我還看到一篇文章NodeJS response.write not working within callback最近發佈,但他的解決方案不適合我。我的主要目標是使用Nodejs創建的簡單MVC結構,而不使用其他模板(如expressjs)來爲數據庫查詢提供html。謝謝。