创建了一个基本的 express.js 应用程序并添加了一个模型(使用 thinky 和 rethinkdb),试图将 changesfeed 传递给玉文件,但无法弄清楚如何传递 feed 的结果。我的理解是 changes() 返回无限光标。所以它总是在等待新的数据。如何在快递中处理。知道我在这里想念什么吗?
var express = require('express');
var router = express.Router();
var thinky = require('thinky')();
var type = thinky.type;
var r = thinky.r;
var User = thinky.createModel('User', {
name: type.string()
});
//end of thinky code to create the model
// GET home page.
router.get('/', function (req, res) {
var user = new User({name: req.query.author});
user.save().then(function(result) {
console.log(result);
});
//User.run().then(function (result) {
//res.render('index', { title: 'Express', result: result });
//});
User.changes().then(function (feed) {
feed.each(function (err, doc) { console.log(doc);}); //pass doc to the res
res.render('index', { title: 'Express', doc: doc}) //doc is undefined when I run the application. Why?
});
});
module.exports = router;