在 Sails 中显示 PostController.js 发送的字符串变量的 ejs 代码

ejs code to display a string variable sent by PostController.js in Sails

试图在 SailsPostController.js 发送的 postview.ejs 中显示字符串变量

val是字符串变量

[ ejs html javascript 远洋快递 node.js ]

PostController.js

module.exports = {

post : function (req, res) {
     var val = req.param('valeur');
     console.log('val =', valeur); // controller test : no problem so far
     res.render('postview')

postview.ejs (?)

  <html>
  <h1>Post view</h1>
  <body>

// until now everything is running smoothly  

  <script type=«text/javascript»>
    document.write ('your value :' + val)
  </script>

  </body>
  </html>

ejs 代码不起作用:javascript 与此处相关吗?

Sails 中在 return 视图中显示 val 字符串的正确代码是什么?

您首先需要将您想要的数据传递到您的视图中。

res.render('postview', {val: val})

然后使用 EJS 模板,您将使用以下代码来呈现该值 <%= val %>