简体   繁体   English

从控制器将JavaScript ojbect嵌入到玉器模板中

[英]embed javascript ojbect in jade template from controller

I'm using jade to do all my rendering, and I"m passing my data from my controller in node into my page template. 我正在使用jade进行所有渲染,并将数据从节点中的控制器传递到页面模板中。

I want to add an object inline with javascript... I have a variable app in a js file, and I want to include more data into that app object. 我想添加一个内联JavaScript的对象...我在js文件中有一个变量应用程序,并且我想在该应用程序对象中包含更多数据。 I have the following: 我有以下几点:

 script(type="text/javascript")
    app.stations = !{page_data.station_info}

Which I would want to output as 我想输出为

 script(trype="text/javascript")
   app.stations = [{my json object}]

But instead it's rendering like this: 但是相反,它是这样渲染的:

 <script type="text/javascript">
     <app class="stations">= [my json object]
 </app>

EDIT: After an hour of research I figured it out: (you need to put a . after script 编辑:经过一个小时的研究,我弄清楚了:(您需要在脚本后加上。

 script.
   app.stations = JSON STUFF

After an hour of research I was able to figure it out... You do script. 经过一个小时的研究,我得以弄清楚...您编写脚本。 and then write your javascript normally. 然后正常编写您的JavaScript。 See below 见下文

 script.
    app.stations = JSON STUFF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM