sails.js 0.10.0-rc4无法将消息刷新到ejs视图 [英] sails.js 0.10.0-rc4 cannot flash message to ejs view

查看:34
本文介绍了sails.js 0.10.0-rc4无法将消息刷新到ejs视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在服务器js中

 if (!user) {
      if (isEmail) {
        req.flash('error', 'Error.Passport.Email.NotFound');
        sails.log.warn('User Email not fond.');
      } else {
        req.flash('error', 'Error.Passport.Username.NotFound');
        sails.log.warn('User name not found.');
      }

ejs视图

<form role="form" action="/auth/local" method="post">
    <input type="text" name="identifier" placeholder="Username or Email">
    <input type="password" name="password" placeholder="Password">
    <button type="submit">Sign in</button>
</form>

<% if (typeof message!== 'undefined') { %>
<%= message %>
<% } else { %>
You E-mail and passport is correct!
<% } %>

如果我输入了错误的电子邮件或护照,则ejs视图不显示任何错误消息,为什么?如何将错误消息刷新到ejs视图?我做错了什么吗?对不起,我的英语不好.谢谢.

if I input one wrong email or passport,the ejs view donot show any error message,why? How can I flash the error message to the ejs view?am I do something wrong? Sorry for my poor English. Thx.

推荐答案

Flash中间件将Flash消息存储在会话中.您仍然必须将其传递到视图并自己渲染:

The flash middleware stores the flash message in a session. You still have to pass it to your view and render it by yourself:

app.get('/flash', function(req, res){
  // Set a flash message by passing the key, followed by the value, to req.flash().
  req.flash('info', 'Flash is back!')
  res.redirect('/');
});

app.get('/', function(req, res){
  // Get an array of flash messages by passing the key to req.flash()
  res.render('index', { messages: req.flash('info') });
});

这篇关于sails.js 0.10.0-rc4无法将消息刷新到ejs视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆