首页 文章

离子检索JSON数据

提问于
浏览
0

我有以下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;
    });
})

2 回答

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

相关问题