2017-04-21 90 views
-1

我在做Lynda關於Ionic框架的教程,一旦我終於進入一些後端編碼,我遇到了這個問題。基本上剛剛生成的應用程序,並打開了WWW/JS/app.js文件到控制器添加到它與此代碼:無法檢索JSON數據使用Ionic AngularJS框架

.controller('ListController', ['$scope', '$http', function($scope, $http){ 
    $http.get('js/data.json').success(function(data){ 
     $scope.artists = data; 
    }); 
}]); 

WWW/JS/data.json是與數據的上傳.json文件我應該使用此代碼來引用index.html文件中:

<ion-item ng-repeat='item in artists' class="item-thumbnail-left item-text-wrap"> 
    <img src="img/{{item.shortname}}_tn.jpg" alt="{{item.name}} Photo"> 
    <h2>{{item.name}}</h2> 
    <h3>{{item.reknown}}</h3> 
    <p>{{item.bio}}</p> 
</ion-item> 

但檢索的數據爲空,如img標籤顯示經檢查沒有價值,同樣包含「項目其它任何標籤'數據參考。我可以嘗試什麼?

+0

你在控制檯有錯誤? –

+0

我使用記事本++作爲我的編輯器...對不起。 – user1938007

+0

從網絡瀏覽器控制檯我的意思是。 –

回答

1

you can try replacing data with below code: 
 

 
$scope.artists = data.artists; 
 

 
OR 
 

 
$scope.artists = data.speakers;

+0

非常感謝,將其更改爲'$ scope.artists = data.artists'使其起作用, – user1938007

+0

可以將它標記爲答案請 –

+0

是的,當然。再次感謝。 – user1938007