0

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

4

1 回答 1

0

我用这段代码修复了它。

if errors
      for each in errors
        p.error #{each.msg}

我通过试验这段代码找到了解决方案,然后在jade中实现它。

for (each in errors) {
      console.log(errors[each].msg);
    }
于 2017-03-14T20:05:10.097 回答