2014-02-17 86 views
1

我正在使用angularjs 1.2.8grails 2.3.4后端。我正在通过grails Resources标记提供Restful Api。json没有数据

我有一个观点是我加载数据:

<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> 

我使用searchController加载数据:

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(); 
}); 

但是在我的PostgreSQL数据库没有可用的数据,但我只有得到:

enter image description here

并且根本没有厚望:

enter image description here

任何建议我能做些什么检查?

PS .:控制器已加载!

UPDATE

使用

<tr ng-repeat="p in product track by p.id"> 

我得到一个错误:

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

JSON表示看起来像这样:

[{"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"}]

+0

你能告诉你的数据(产品)JSON表示?我虽然那个ID是一个唯一的密钥 –

+0

@IlanFrumer请看我的更新! – mrquad

+1

检查你的数据,看看是否有未定义的ID - >这是错误的含义。 –

回答

1

修复ngRepeat语法:

<tr ng-repeat="p in product track by p.id"> 
+1

好的thx寻求你的帮助和支持。睡了一晚后发现错误。在json url中是一个简单的's';( – mrquad