2016-07-28 50 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