嗨,我一直在学习本教程,但遇到了问题。
在我的 edit.jade 文件中,我有这个 -
form(method="POST", action="/users/")
input(type="hidden", name="_method", value="PUT")
p Name:
input#name(type="text", name="name", value="#{user.name}")
p Email:
input#email(type="email", name="email", value="#{user.email}")
p Age:
input#age(type="number", name="age", value="#{user.age}")
p: button(type="submit") Update
我用这段代码调用视图 -
app.param('name', function (req, res, next, name){
Users.find({ name: name }, function (err, docs) {
req.user = docs[0];
next();
});
});
app.get('/users/:name/edit', function (req, res){
res.render("users/edit", { user: req.user });
});
但是,在渲染 edit.jade 文件时,会抛出此错误 -
ReferenceError: edit.jade:6
4| input(type="hidden", name="_method", value="PUT")
5| p Name:
> 6| input#name(type="text", name="name", value="#{user.name}")
7| p Email:
8| input#email(type="email", name="email", value="#{user.email}")
9| p Age:
user is not defined
at eval (eval at <anonymous> (/usr/local/lib/node_modules/jade/lib/jade.js:171:8),<anonymous>:32:99)
at /usr/local/lib/node_modules/jade/lib/jade.js:172:35
at /usr/local/lib/node_modules/jade/bin/jade:154:17
at /usr/local/lib/node_modules/jade/node_modules/mkdirp/index.js:38:26
at Object.oncomplete (fs.js:107:15)
这对我来说毫无意义。它确实使用字段中的正确值呈现页面,但我无法提交表单。想法?