我正在尝试按照本教程将信息从 JSON 对象显示到视图
我希望在标题为“allBusinesses”的视图上呈现 JSON
我可以通过以下方式将原始 JSON 打印到屏幕上:
public static Result getBusinesses()
{
List<Business> businesses = new Model.Finder(String.class, Business.class).all();
return ok(Json.toJson(businesses)); //displays JSON object on empty page
}
然后我可以渲染 allBusinesses 页面:
public static Result goToAllBusinessesPage()
{
return ok(allBusinesses.render());
}
allBusinesses.scala.html 看起来像:
@main("All businesses"){
<ul id="businesses"></ul>
}
jQuery/coffeescript 内容如下:
$ ->
$.get "/getBusinesses", (data) ->
$.each data, (index, business) ->
$("#businesses").append $("<li>").text business.businessName
我希望 javascript 读取 JSON getBusinesses() 返回并将 business.businessName 属性显示到 allBusinesses 页面