[英]Bootstrapping JSON data into Scala PlayFramework templates
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. 目标是从用Scala编写的Model / ViewModel转换为可以引导到视图模板中的原始JSON,以避免在页面加载后发出对JSON数据的请求。
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. 没有太多运气与谷歌或PlayFramework文档,所以我喜欢一些帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.