离子检索JSON数据

时间:2016-06-10 05:51:23

标签: angularjs json ionic-framework controller

我有以下JSON,我在检索数据并在IONIC中显示时遇到问题。有人可以给我一些指导吗?

JSON

mynews_JsonCallBack({
"items":[
{"headline":"Cat",
"link":"http://www.mynews.com/1",
"description":"Yellow cat",
"pubdate":"Fri, 10 Jun 2016 06:00:19",
"image":"http://www.mynews.com/1.jpg"},
{"headline":"Dog",
"link":"http://www.mynews.com/2",
"description":"Blue dog",
"pubdate":"Fri, 10 Jun 2016 06:00:19",
"image":"http://www.mynews.com/2.jpg"}
]});

控制器

.controller('NewsCtrl', function($http, $scope) {
  $scope.news = [];
  $http.get('https://www.mynews.com/.json')
    .success(function(response) {
      $scope.news.push = response.headline;
    });
})

3 个答案:

答案 0 :(得分:0)

试试这个

<ion list>
  <ion item ng-repeat = "title in news">
     {{title}}
  </ion item>
</ion list>
控制器中的

.controller('NewsCtrl', function($http, $scope) {
 $scope.news = [];
  $http.get('https://www.mynews.com/.json')
    .success(function(response) {
      $scope.res = response.item;
        $scope.res.forEach(function(item) {
             $scope.news.push(item.headline);
         });
        console.log($scope.news);
    })
    .error(function(response){
     console.log(response);
    });

});

答案 1 :(得分:0)

试试这个

$scope.news = [];

.controller('NewsCtrl', function($http, $scope) {

  $http.get('https://www.mynews.com/.json')
    .success(function(response) {
      $scope.res = response.items[0];
            $scope.news.push($scope.res);
      })
    });
})

<ion-list>
  <ion-item ng-repeat="item in news">
  {{item.headline}}!
  </ion-item>
</ion-list>

答案 2 :(得分:0)

尝试

VMConfig.localhost

代替

$scope.news.push = response[0].headline;