在JSON没有数据 [英] No data over json
问题描述
我使用 angularjs 1.2.8
与 Grails的2.3.4
后端。我过的Grails提供了一个RESTful的API 资源
标记。
我有一个观点是我加载数据:
< DIV CLASS =集装箱主框架NG-应用=testapp
NG-控制器=searchControllerNG-的init =的init()>
< H1类=页面页眉>产品< / H1>
<表类=表>
<&THEAD GT;
&所述; TR>
百分位宽度=25像素> ID< /第i
<第i TITLE< /第i
<第i个;价格< /第i
<第i说明< /第i
百分位宽度=50像素>< /第i
< / TR>
< / THEAD>
<&TBODY GT;
< TR NG重复=P由$ ID产品>
&所述; TD> {{p.id}}&下; / TD>
&所述; TD> {{p.title}}&下; / TD>
&所述; TD> {{p.price}}&下; / TD>
&所述; TD> {{p.description}}&下; / TD>
<! - 纳克秀=user.id和放大器;&安培; user.id == e.user_id - >
< / TR>
< / TBODY>
< /表>
<! - 纳克秀=user.username - >
&所述p为H.;
< / DIV>
我使用的是 searchController
加载数据:
testapp.controller(searchController功能($范围,$ rootScope,$ HTTP,$位置){
无功负荷=功能(){
的console.log('呼叫负载()...'); VAR URL ='products.json'; 如果($ rootScope&放大器;&安培; $ rootScope.appUrl){
URL = $ rootScope.appUrl +'/'+ URL;
} $ http.get(URL)
.success(功能(数据,状态,头,配置){
$ scope.product =数据;
angular.copy($ scope.product,$ scope.copy);
});
} 加载();
});
然而,在我的PostgreSQL数据库有可用的数据,但我只得到:
和没有厚望可言:
任何建议我能做些什么检查?
PS:控制器装!
更新
使用
< TR NG重复=P由p.id产品跟踪>
我得到一个错误:
错误:[ngRepeat:受骗者] http://errors.angularjs.org/1.2.8/ngRepeat/dupes?p0=p%20in%20product%20track%20by%20p.id&p1=undefined
在错误(原生)
在https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:6:449
在https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:184:445
在Object.fn(https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:99:371)
在小时。$摘要(https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:100:299)
在小时。$应用(https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:103:100)
在f(https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:67:98)
在E(https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:71:85)
在XMLHtt prequest.v.onreadystatechange(https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:72:133)angular.js:9413
UPDATE2
JSON的再presentation看起来像:
<$c$c>[{\"class\":\"com.testapp.Product.BasicProduct\",\"id\":1,\"dateCreated\":\"2014-02-17T13:43:13Z\",\"description\":\"blblblblbalablablalbalbablablablablblabalalbllba\",\"lastUpdated\":\"2014-02-17T13:43:13Z\",\"price\":5.0,\"title\":\"Product1\"},{\"class\":\"com.testapp.Product.BasicProduct\",\"id\":2,\"dateCreated\":\"2014-02-17T13:43:13Z\",\"description\":\"blblblblbalablablalbalbablablablablblabalalbllba\",\"lastUpdated\":\"2014-02-17T13:43:13Z\",\"price\":75.0,\"title\":\"Product2\"},{\"class\":\"com.testapp.Product.BasicProduct\",\"id\":3,\"dateCreated\":\"2014-02-17T13:43:13Z\",\"description\":\"blblblblbalablablalbalbablablablablblabalalbllba\",\"lastUpdated\":\"2014-02-17T13:43:13Z\",\"price\":50.0,\"title\":\"Product3\"},{\"class\":\"com.testapp.Product.BasicProduct\",\"id\":4,\"dateCreated\":\"2014-02-17T13:43:13Z\",\"description\":\"blblblblbalablablalbalbablablablablblabalalbllba\",\"lastUpdated\":\"2014-02-17T13:43:13Z\",\"price\":25.0,\"title\":\"Product4\"},{\"class\":\"com.testapp.Product.BasicProduct\",\"id\":5,\"dateCreated\":\"2014-02-17T13:43:13Z\",\"description\":\"blblblblbalablablalbalbablablablablblabalalbllba\",\"lastUpdated\":\"2014-02-17T13:43:13Z\",\"price\":15.0,\"title\":\"Product5\"}]$c$c>
块引用>解决方案修复
ngRepeat
语法:&LT; TR NG重复=P由p.id产品跟踪&GT;
I am using
angularjs 1.2.8
withgrails 2.3.4
backend. I am providing a Restful Api over the grailsResources
tag.I have a view were I load the data:
<div class="container main-frame" ng-app="testapp" ng-controller="searchController" ng-init="init()"> <h1 class="page-header">Products</h1> <table class="table"> <thead> <tr> <th width="25px">ID</th> <th>TITLE</th> <th>PRICE</th> <th>Description</th> <th width="50px"></th> </tr> </thead> <tbody> <tr ng-repeat="p in product by $id"> <td>{{p.id}}</td> <td>{{p.title}}</td> <td>{{p.price}}</td> <td>{{p.description}}</td> <!-- ng-show="user.id &&user.id==e.user_id" --> </tr> </tbody> </table> <!-- ng-show="user.username" --> <p> </div>
I am using the
searchController
to load the data:testapp.controller("searchController", function($scope, $rootScope, $http, $location) { var load = function() { console.log('call load()...'); var url = 'products.json'; if ($rootScope && $rootScope.appUrl) { url = $rootScope.appUrl + '/' + url; } $http.get(url) .success(function(data, status, headers, config) { $scope.product = data; angular.copy($scope.product, $scope.copy); }); } load(); });
However in my postgresql db there is data available, but I only get:
and no expection at all:
Any suggestions what I can do to check that?
PS.: Controller is loaded!
UPDATE
Using
<tr ng-repeat="p in product track by p.id">
I am getting an error:
Error: [ngRepeat:dupes] http://errors.angularjs.org/1.2.8/ngRepeat/dupes?p0=p%20in%20product%20track%20by%20p.id&p1=undefined at Error (native) at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:6:449 at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:184:445 at Object.fn (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:99:371) at h.$digest (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:100:299) at h.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:103:100) at f (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:67:98) at E (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:71:85) at XMLHttpRequest.v.onreadystatechange (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:72:133) angular.js:9413
UPDATE2
The json representation looks like that:
[{"class":"com.testapp.Product.BasicProduct","id":1,"dateCreated":"2014-02-17T13:43:13Z","description":"blblblblbalablablalbalbablablablablblabalalbllba","lastUpdated":"2014-02-17T13:43:13Z","price":5.0,"title":"Product1"},{"class":"com.testapp.Product.BasicProduct","id":2,"dateCreated":"2014-02-17T13:43:13Z","description":"blblblblbalablablalbalbablablablablblabalalbllba","lastUpdated":"2014-02-17T13:43:13Z","price":75.0,"title":"Product2"},{"class":"com.testapp.Product.BasicProduct","id":3,"dateCreated":"2014-02-17T13:43:13Z","description":"blblblblbalablablalbalbablablablablblabalalbllba","lastUpdated":"2014-02-17T13:43:13Z","price":50.0,"title":"Product3"},{"class":"com.testapp.Product.BasicProduct","id":4,"dateCreated":"2014-02-17T13:43:13Z","description":"blblblblbalablablalbalbablablablablblabalalbllba","lastUpdated":"2014-02-17T13:43:13Z","price":25.0,"title":"Product4"},{"class":"com.testapp.Product.BasicProduct","id":5,"dateCreated":"2014-02-17T13:43:13Z","description":"blblblblbalablablalbalbablablablablblabalalbllba","lastUpdated":"2014-02-17T13:43:13Z","price":15.0,"title":"Product5"}]
解决方案Fix the
ngRepeat
syntax:<tr ng-repeat="p in product track by p.id">
这篇关于在JSON没有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!