[英]How can I pass JS objects from the server-side to the clientside in NodeJS
In PHP I used to pass objects from the backend to the front end in JSON form, using script tags. 在PHP中,我曾经使用脚本标记以JSON形式将对象从后端传递到前端。
<script>
var serversideStuff = '<?php echo json_encode($serversideArray); ?>';
</script>
How can I pass JS objects from the server-side to the clientside using nodeJS, express and Jade. 如何使用nodeJS,express和Jade将JS对象从服务器端传递到客户端。 There is probably a really good way that I'm just not aware of.
可能有一种我不知道的好方法。
Hope you can help me out. 希望你能帮助我。
In PHP you use bad practices (dynamically generating javascript as part of an application). 在PHP中,您使用不良做法(动态生成javascript作为应用程序的一部分)。
With node you do it right. 使用节点,您可以正确执行。 This means you
这意味着你
<script type="text/javascript">
var clientVar = {{JSON.stringify(serverVar)}}
</script>
change {{}} to whatever your template engine uses to interpret code 将{{}}更改为模板引擎用于解释代码的任何内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.