简体   繁体   English

将Json嵌入Scalate中

[英]Embedding Json in Scalate

I want to embed JSON in the DOM as outlined in the below question: 我想将JSON嵌入到DOM中,如以下问题所述:

Best practice for embedding arbitrary JSON in the DOM? 在DOM中嵌入任意JSON的最佳实践?

However I can't figure out how to do this with Scalate/Scalatra. 但是我不知道如何使用Scalate / Scalatra做到这一点。 I have this in my scaml template: 我的骗局模板中有这个:

-@ val fullStateJson: String

and I can render it via 我可以通过渲染它

%div= fullStateJson

but I can't figure out how to get this into a <script> . 但我不知道如何将其放入<script> When I do 当我做

%script(type="application/json" id="fullStateScript") =fullStateJson

It ends up escaped, like 最终逃脱了,就像

{&quot;45&quot;:{&quot;id&quot;:45,&quot;level&quot;:0},&quot;98&quot;:{&quot;id&quot;:98,&quot;level&quot;:0}}

The TemplateEngine.escapeMarkup is set to true by default, so it changes the html special characters. 默认情况下, TemplateEngine.escapeMarkup设置为true,因此它将更改html特殊字符。

You can put this in your template: <% escapeMarkup = false %> 您可以将其放在模板中: <% escapeMarkup = false %>

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

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