2017-04-21 94 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