0
我有一個使用AngularJS進行視圖的Play框架項目。負責查詢數據的控制器發出2個請求,每個請求返回一個JSON塊。第一個工作正常,並顯示正確。第二個數據幾乎被Angular摧毀了(下面的例子)。AngularJS不能正確處理JSON
JSON在呈現前正確創建,因爲它通過應用程序的日誌顯示。 這是正確的JSON(從Play框架路由方法的記錄所採取的):
{"id":5,"name":"auditoria","url":null,"version":1,"methods":[]}
這是AngularJS如何打印它。它標記化:
[{},{"0":"a","1":"u","2":"d","3":"i","4":"t","5":"o","6":"r","7":"i","8":"a"},{},{},{"length":0}]
而這裏的控制器:
app.controller("ViewCtrl", [ "$scope", "$resource", "$routeParams", "apiUrl",
function($scope, $resource, $routeParams, apiUrl) {
var ServiceList = $resource(apiUrl + "/services");
$scope.services = ServiceList.query(); //JSON is displayed properly
if ($routeParams.id) {
jsonServicoQuery = apiUrl + "/services/" + $routeParams.id
var Service = $resource(jsonServicoQuery);
$scope.currentService = Service.query(); //JSON is butchered
}
} ]);
這裏的HTML:
<div class="row">
<div class="col-md-3">
<div class="bs-sidebar hidden-print" role="complementary">
<ul class="nav bs-sidenav">
<li><a href="/create"><i class="fa fa-plus"></i></a></li>
<li ng-repeat="s in services| orderBy:'name'"><a
href="/view/{{s.id}}">{{s.nome}}</a>
<ul>
<li ng-repeat="m in s.methods| orderBy:'name'">{{m.name}}
[{{m.id}}]</li>
</ul></li>
</ul>
</div>
</div>
<div class="col-md-9" role="main">
<div class="bs-docs-section">
<div class="page-header">
<!-- displaying the whole currentService JSON for debugging purposes -->
{{currentService}}
</div>
</div>
</div>
</div>
任何人有什麼我做錯了什麼線索?
更新: Service.query()執行由遊戲框架路由的方法。
路由配置:
GET /api/services/:id controllers.Services.show(id: String)
而且controllers.Services.show(id: String)
實現:
public static Result show(String id) {
Service s = Service.findById(id);
//JSON displayed here is correct, log below
Logger.info("At Services show, json " + Json.toJson(s));
return ok(Json.toJson(s));
}
登錄:
[info] application - At Services show, json {"id":5,"name":"auditoria","url":null,"version":1,"methods":[]}
看起來你的服務有問題。你可以發佈你的Service.query()的內容嗎? – 2014-09-29 16:52:00