我有一个简单的应用程序,它使用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