我正在尝试如下非常基本的车把模板:
// movies.hbs
<h1>Movies</h1>
<ul>
{{#for movies}}
{{#if this}}
<li><a href="http://www.imdb.com/title/{{ this.title }}">{{ this.title }}, {{ this.year }}
{{this.genre}}</a>
</li>
{{else}}
<li>No movies found.</li>
{{/if}}
{{/for}}
</ul>
但是,当我使用MongoDB数据库中检索到的文档进行渲染时,
MongoClient.connect("mongodb://localhost:27017/vidoes", function(err, db) {
if (err) throw err;
db.collection('movies').find({}).toArray(function(err, docs) {
if (err) throw err;
app.get('/', function(req, res){
res.render('movies', {'movies':docs});
});
app.use(function(req, res){
res.sendStatus(404);
});
var server = app.listen(3000, function() {
var port = server.address().port;
console.log("Express server listening on port %s.", port);
});
});
});
我收到奇怪的错误:
$ node app.js
Express server listening on port 3000.
Error: Missing helper: "for"
at Object.<anonymous> (/public_html/All Together Now/node_modules/handlebars/dist/cjs/handlebars/helpers/helper-missing.js:19:13)
at Object.eval [as main] (eval at createFunctionContext (/public_html/All Together Now/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:23), <anonymous>:6:89)
当我尝试不使用数据库时,它给了我同样的错误。当然,在我访问主页之后。
app.get('/', function(req, res){
var docs = [{ "title" : "Minuscule: Valley of the Lost Ants (Minuscule - La vallée des fourmis perdues)", "genre" : "Adventure|Animation|Children", "year" : 1993 },
{ "title" : "Bambi Meets Godzilla", "genre" : "Animation|Comedy", "year" : 2003 },
{ "title" : "Annie Get Your Gun", "genre" : "Musical|Western", "year" : 2011 },
{ "title" : "Scary Movie 5 (Scary MoVie)", "genre" : "Comedy", "year" : 2005 }
];
res.render('movies', {'movies':docs});
});
var server = app.listen(3000, function() {
var port = server.address().port;
console.log("Express server listening on port %s.", port);
});
任何帮助将不胜感激。
CS
答案 0 :(得分:1)
您应该尝试使用mysql> update messages set read=1 where id=4;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read=1 where id=4' at line 1
mysql> show columns from messages;
+-------------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+---------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| account_id | varchar(255) | NO | | NULL | |
| subject | varchar(2048) | NO | | NULL | |
| message | text | NO | | NULL | |
| message_id | int(11) | NO | | 0 | |
| read | int(11) | NO | | 0 | |
| replied | int(11) | NO | | 0 | |
| priority | int(11) | NO | | 0 | |
| topic | int(11) | NO | | 0 | |
| user_deleted | int(11) | NO | | 0 | |
| created | datetime | NO | | NULL | |
| modified | datetime | NO | | NULL | |
| to_user_id | int(11) | NO | | 0 | |
| recipient_deleted | int(11) | NO | | 0 | |
| recipient_read | int(11) | NO | | 0 | |
+-------------------+---------------+------+-----+---------+----------------+
15 rows in set (0.00 sec)
。在下面看看。
each
如果您想使用一些额外的东西,那么我将参考创建帮助器 https://gist.github.com/LeCoupa/6176077a9a8e2ad00eda