简体   繁体   English

玩! 2从Controller在View中呈现JSON数据

[英]Play! 2 Rendering JSON data in View from Controller

based on this http://www.markhneedham.com/blog/2012/10/14/play-framework-2-0-rendering-json-data-in-the-view/ 基于此http://www.markhneedham.com/blog/2012/10/14/play-framework-2-0-rendering-json-data-in-the-view/

myview: 我的观点:

    @(message: String)(myobjects:ObjectNode)
@import com.fasterxml.jackson.databind.JsonNode
@import com.fasterxml.jackson.databind.node.ObjectNode

controller: 控制器:

ObjectNode myobjects = objectsDAO.getObjects();
return ok(myview.render("test",myobjects ));

error 错误

 not found: type ObjectNode

Doesn't seem to work with ObjectNode, the imports in the view don't seem to be working. 似乎无法与ObjectNode一起使用,视图中的导入似乎不起作用。 Could not find much documentation about passing the view a JSON 找不到太多有关将视图传递给JSON的文档

Try defining it as such: @(message: String, myobjects:com.fasterxml.jackson.databind.node.ObjectNode) , or if that doesn't work, put the @imports in your main.scala.html since it holds the content of your other views.... 尝试这样定义它: @(message: String, myobjects:com.fasterxml.jackson.databind.node.ObjectNode) ,或者,如果这样不起作用,则将@imports放入您的main.scala.html因为它保存了您其他视图的内容...。

<body>
    @content
</body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM