playframework JsValue in HTML Template

2019-01-19 15:26发布

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>

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?

1条回答
叼着烟拽天下
2楼-- · 2019-01-19 15:35

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

var org = @Html(Json.stringify(Json.toJson(org)));
查看更多
登录 后发表回答