从车把转换为玉

时间:2019-07-16 19:13:30

标签: node.js templates error-handling handlebars.js pug

我在尝试将一些代码从Handlebars转换为Jade时遇到问题。我正在创建注册表格,并希望它能够检查错误。除此以外,我所有的代码都有效

{{#if error}}
    {{#each errors}}
        <div class-"alert alert-danger">{{msg}}</div>
    {{/each}}
{{/if}}

。这是HBS格式,我无法在线找到转换器。有谁知道我想念的在线转换器?还是可以替我转换?

----需要转换为玉的代码------

{{#if error}}
    {{#each errors}}
        <div class-"alert alert-danger">{{msg}}</div>
    {{/each}}
   {{/if}}

-----注册已转换为玉的代码-----------------------

 h2 Register
    form(method='post', action='/users/register')
        .form-group
            label Name
            input.form-control(type='text', placeholder='Name', name='name')
        .form-group
            label Username
            input.form-control(type='text', placeholder='Username', name='username')
        .form-group
            label Email
            input.form-control(type='email', placeholder='Email', name='email')
        .form-group
            label Password
            input.form-control(type='password', placeholder='Password', name='password')
        .form-group
            label Confirm Password
            input.form-control(type='password', placeholder='password', name='password2')
        button.btn.btn-default(type='submit') Submit

----其中一些与user.js相关-------------------------------------- -------

 //register
router.post('/register', (req, res) => {
var name = req.body.name;
var email = req.body.email;
var username = req.body.username;
var password = req.body.password;
var password2 = req.body.password2;

//validations
req.checkBody('name', 'Name is required').notEmpty();
req.checkBody('email', 'Email is required').notEmpty();
req.checkBody('email', 'Email is not valid').isEmail();
req.checkBody('Username', 'Username is required').notEmpty();
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
    });
} else {
    console.log('Passed');
}
  });

我希望代码在注册阶段检查错误。如果有人没有输入相同的密码,则会弹出错误提示。

0 个答案:

没有答案