Reputation: 4842
Goal is to go from a Model/ViewModel written in Scala to raw JSON that can be bootstrapped into the view template so as to avoid making requests for the JSON data after the page load.
And example of what I've been playing around with but I haven't had much luck:
@(todos: play.api.libs.json.JsValue)
@import play.api.libs.json.Json
<html>
<head>...</head>
<body>...</body>
<script>
var todos = JSON.parse(' @Json.stringify(todos) ');
</script>
</html>
Basically its spitting out a lot of quoted text to the effect of:
[{"id":":"294858e2-c9eb-4f50-9eac-47b257573d83"}]
Haven't had much luck with Google or the PlayFramework docs so I'd love some help.
Upvotes: 5
Views: 1883