gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 16:54:58 25 4
gpt4 key购买 nike

尝试在 Sails 中的 PostController.js 发送的 postview.ejs 中显示字符串变量

val是字符串变量

[ ejs html javascript Sails express 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 中在返回 View 中显示 val 字符串的正确代码是什么?

最佳答案

您首先需要将所需的数据传递到您的 View 中。

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

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

关于javascript - 在 Sails 中显示 PostController.js 发送的字符串变量的 ejs 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29866971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com