我试图在提交注册表单时显示错误,但错误以下列方式显示(其中每行是 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 中的代码是正确的,但我也不知道该怎么做。