Playframework - 在视图中显示Json

时间:2014-12-19 06:14:33

标签: json playframework views

我面临编译错误"未指定的值参数内容"当我尝试将json节点发送到视图时。该错误发生在bo.scala.html的第3行。

感谢您的帮助

在我的控制器中 - Application.java

//send jsonNode to view table 
public static Result showReportsUniverses() throws SDKException {
    ArrayList<BiObjectsInfos> boobjects = BiFunctions.getReportsUniverses(user, 
            password, cms, apsAuthType);
    return ok(bo.render(Json.toJson(boobjects)));  
}

我的路线

GET      /boobjects                 controllers.Application.showReportsUniverses()

我的观点 - bo.scala.html -

@()

@table(){
    // boobjects handles the JsonNode boobjects
    <script src="@routes.Assets.at("javascripts/boobjects.js")" type="text/javascript"></script>

    <tbody id= "boobjects" \>
        <tr>
            <th>Reports</th>
            <th>Universes</th>
}

我的观点 - table.scala.html -

@(content : Html)

<!DOCTYPE html>
<html>
    <head>
        <title>Bla</title>
        <link rel="stylesheet" href="@routes.Assets.at("css/table.css")" >
        <script src="@routes.Assets.at("javascripts/jquery-1.11.1.min.js")" type="text/javascript"></script>    
   </head>
    <body>
        <table>
            @content
        </table>
    </body>
</html>

我的咖啡脚本boobjects.js

$ ->
   $.get "/boobjects", (boobjects) ->
    $.each boobjects, (index, boObj) ->
      $("#boobjects").append $("<tr>")
      $("#boobjects").append $("<td>").text boObj.si_name
      $("#boobjects").append $("<td>").text boObj.universe_name

1 个答案:

答案 0 :(得分:0)

return ok(boobjects.render(toJson(boobjects)));

应该阅读

return ok(boobjects.render(Json.toJson(boobjects)));