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

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

问题描述

我试图在JsValue的play(v2.2.2)模板中定义一个json对象。问题是,被转换为& quot;

  @(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; ...更多数据...}; 

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

解决方案定义它为 Html ,所以它不会自动转义。

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


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 &quot;

@(org: db.Tables.OrganizationRow)

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

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

results in:

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

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

解决方案

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天全站免登陆