HTML 模板中的 playframework JsValue [英] playframework JsValue in HTML Template

查看:20
本文介绍了HTML 模板中的 playframework JsValue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在模板中定义一个具有播放 JsValue 的 json 对象(v2.2.2).问题是,"被转换为"

I'm trying to define a json object in the template with the JsValue of play (v2.2.2). The problem is, " is converted to "

@(org: db.Tables.OrganizationRow)

@import models.format.EntityFormat._
@import play.api.libs.json.Json

<script  type="text/javascript">
    var org = @Json.toJson(org);
</script>

结果:

{&quot;id&quot;:16,&quot;userid&quot;:&quot; ... more data ... };

如何在 scala html 模板中获得正确的 json?

How I'm able to get the correct json in the scala html template?

推荐答案

将其定义为 Html 以免自动转义.

Define it as Html so it doesn't automatically get escaped.

var org = @Html(Json.stringify(Json.toJson(org)));

这篇关于HTML 模板中的 playframework JsValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆