2016-07-28 48 views
0

我开始使用hackathon starter github repo here来构建一个node.js express应用程序,但很快就意识到我需要改变一些东西。我现在使用小胡子,但仍想显示闪光消息。它看起来像{{messages.errors}}包含一些信息,但当我登录这个控制台时显示的是[object,Object]。node.js中的胡须模板中的flash消息

如何查看这些对象的内容?

的flash.mustache文件看起来像:

<script> 
if ("{{messages.errors}}" != ""){ 
    console.log({{messages()}}) 
    console.log("error", {{messages()}}); // this line is seen as console.log("error",); 
} 
</script> 

和闪存添加到app.js,你会期望与

const flash = require('express-flash'); 
app.use(flash()); 

,并在路线如你所愿闪光灯被处理(举例):

if (!user) { 
    req.flash('errors', { msg: 'Account with that email address does not exist.' }); 
    return res.redirect('/forgot'); 
} 

回答

0

要得到消息尝试messages.errors.msg

或者您可以储存这样的消息req.flash('errors', 'Account with that email address does not exist.'),然后获取消息messages.errors