离子:为什么我的图像没有从我的json文件加载?

时间:2015-07-17 00:53:26

标签: javascript json ionic photos

我试图将我的json文件中的图像加载到我的应用程序中,但我无法让它工作:

这是我的代码:

JS:

.controller('photoCtrl', function($scope, $ionicModal, $ionicBackdrop, $ionicScrollDelegate, $ionicSlideBoxDelegate, $http) {
   $scope.images = [];

    $scope.getImages = function() {
        $http.get('https://api.myjson.com/bins/37ia6')
            .success(function(data) {
                $scope.images = data.images;
            })
    }

HTML:

<ion-view view-title="Gallery" align-title="center" ng-controller="photoCtrl" >

  <ion-content ng-init="getImages()" class="center" class="has-header padding">

    <!-- start Under6/7/8/9s Photos -->
    <div class="item item-divider">
      <i class="ion-images"></i> Under6/7/8/9s Photos
    </div>
    <a class="item item-list-detail">
      <ion-scroll direction="x">
        <img on-hold="onHold()" ng-repeat="image in images" ng-src="{{images.src}}" ng-click="showImages($index)" class="image-list-thumb" />
      </ion-scroll>
    </a>
</ion-content>
</ion-view>

2 个答案:

答案 0 :(得分:1)

我认为原因在于你的JSON。迭代时你会发生什么:

{"images":"http://cdn.caughtoffside.com/wp-content/uploads/2012/07/Marko-Marin.jpg"}

可能你的API应该返回一个像

这样的对象数组
[{"src":"http://cdn.caughtoffside.com/.../Marko-Marin.jpg"},
 {"src":"http://cdn.caughtoffside.com/.../Johnny-Blue.jpg"},
 ...
]

迭代对象通常看起来不同:

<div ng-repeat="(key, value) in myObj">

答案 1 :(得分:0)

试试这个:

<ion-scroll direction="x" ng-repeat="image in images"> 
  <img on-hold="onHold()" ng-src="{{image.src}}" ng-click="showImages($index)" class="image-list-thumb" /> 
</ion-scroll>