2015-10-23 64 views
0

我有一些angularJS的問題我無法將json數據顯示到我的html中。 我的代碼是這樣的:不允許在轉發器中複製

app.controller( 'ServerPostsController',函數($範圍,$ HTTP){

$('.loading').show(); 

    $scope.posts=[]; 

     $http.get("https://api.basebear.com/json/tables/20a3fb1d-42c7-45cb-9440-2c6d5d10403d/records?apikey=6e954b0a17b74f52b842ec2b0f0d6d0da24ac5ad"). 
     success(function(data) { 


      $scope.posts=JSON.stringify(data); 
      console.log("ok" + "data"+ $scope.posts); 

     }). 
     error(function() { 
      $('.loading').hide(); 
      console.log("no"); 

      alert("Si è verificato un errore!"); 
     }); 

}); 

,我的HTML是這樣的:

<ons-toolbar fixed-style> 
<div class="left"> 
<ons-toolbar-button onclick="menu.toggleMenu()"> 
<ons-icon icon="ion-navicon" size="28px" fixed-width="false"></ons-icon> 
</ons-toolbar-button> 
</div> 
<div class="center">Prova</div> 
</ons-toolbar> 



<section style="padding: 10px;"> 

    <ons-row style="padding: 10px 0 20px 0;"> 
    <input type="search" placeholder="Search" class="search-input" ng-model="search"> 
    </ons-row> 

    <table> 
    <tr> 
    <th>Id</th> 
    <th>Nome</th> 
    <th>Cognome</th> 
    <th>Data</th> 

</tr> 
    <tr ng-repeat="post in posts"> 
    <td>{{post.Value}}</td> 
    <td>{{post.Value}}</td> 
    <td>{{post.Value}}</td> 
    <td>{{post.Value}}</td> 

</tr> 
</table> 
</section>  

但我有這個錯誤: 不允許在中繼器中複製。使用'track by'表達式來指定唯一鍵。中繼器:在帖子中發佈,重複k ey:string:[,重複值:「[」

如何顯示數據?

回答

0

變化

ng-repeat="post in posts" 

ng-repeat="post in posts track by $index" 

編輯:

查看數據後,我意識到它實際上是一個數組內對象的數組。將其轉換爲對象數組。

另外,如果你沒有訪問API,變化:

$scope.posts = JSON.stringify(data) 

$scope.posts = angular.toJson(data[0]) //I don't think JSON.stringify is required. 
+0

我這樣做,但我dont'see數據;爲什麼? – pinostack

+0

很可能,沒有帖子的屬性「值」。將post.Value更改爲只是發佈,看看它是否顯示任何內容。 –

+0

你能看到我的Json數據嗎? https://api.basebear.com/json/tables/20a3fb1d-42c7-45cb-9440-2c6d5d10403d/records?apikey=6e954b0a17b74f52b842ec2b0f0d6d0da24ac5ad – pinostack

相關問題