我有一個簡單的應用程序,它使用Express和Hoffman視圖引擎來流式傳輸視圖。使用Mongoose的Dust.js流式視圖
我目前正在嘗試擴展由官方Dust.js存儲庫提供的an example。
不幸的是,我不能使它使用Mongoose進行數據檢索。
app.js
var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'dust');
app.engine('dust', hoffman.__express());
app.use(hoffman.stream);
app.get('/', function (req, res) {
res.stream("hello", {
"test": function(chunk, context, bodies, params) {
//This works as expected
//return [{name:"This is a name"},{name:"This is another name"}];
return model.find().lean().exec(function(err, docs) {
return docs;
});
},
"test1": function(chunk, context, bodies, params) {
return modelB.find(function(err, docs) {
return docs;
});
}
});
});
hello.dust
{#test}
<br>{name}
{/test}
{#test1}
<br>{name}
{/test1}
'model.find()'的輸出是什麼?如果你登錄它或什麼的。這是一組文件? – Interrobang
你好@Interrobang,新年快樂。 我的模型返回一個文檔數組。 例如 '[{ _id:5687 cf282018e4df73b62ea8, 名: '插入1451740968750', __v:0 },{ _id:5687 cf282018e4df73b62ea9, 名: '插入1451740968750', __v:0 }] ' – Theodore