2013-07-19 73 views
0

我試圖顯示從JSON對象到一個視圖的信息,下面this tutorialJava玩! - 顯示格式的JSON

我想的JSON對名爲視圖渲染「allBusinesses」

我能打印原始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頁面

+0

我不認爲有可能讓JavaScript調用您的服務器端數據。 – cYn

回答

0

解決:

包括在main.scala.html javascript的需要:

<script src="@routes.Assets.at("javascripts/index.min.js")" type="text/javascript"></script>