【发布时间】:2017-03-15 04:05:10
【问题描述】:
我试图在提交注册表单时显示错误,但错误以下列方式显示(其中每一行是 1 个错误):
[object Object]
[object Object]
[object Object]
[object Object]
验证码
router.post('/register', function(req, res) {
var name = req.body.name;
var email = req.body.email;
var password = req.body.password;
var password2 = req.body.password2;
// validation
req.checkBody('name', 'Name is required').notEmpty();
req.checkBody('email', 'Email is required').notEmpty();
req.checkBody('email', 'Email is not valid').isEmail();
req.checkBody('password', 'Password is required').notEmpty();
req.checkBody('password2', 'Passwords do not match').equals(req.body.password);
var errors = req.validationErrors();
if(errors) {
res.render('register', {
errors:errors
});
console.log("errors");
} else {
console.log('No validation errors');
}
});
玉码
if errors
for each in errors
p #{each}
我不认为 Jade 中的代码是正确的,但我也不知道如何正确。
【问题讨论】:
-
只是为了确定这个问题..您需要知道如何在jade中显示错误?还快速查看错误,您做错了。将您的错误作为字典,将键作为字段,将错误和值作为关联错误的数组,这是一个更好的主意:)
-
@georoot 是的,我想在 Jade 模板中向用户显示错误。关于字典,你将如何实现它?
标签: node.js express messagebox jade4j