javascript - 将图像插入数组

标签 javascript arrays angularjs ionic-framework

我想拍摄不同元素的照片或为一件元素拍摄多张照片,但我正在努力弄清楚如何将图像推送到数组中。

从第一行开始显示单个图像:

<img ng-show="imgURI !== undefined" ng-src="{{imgURI}}" style="text-align: center">

但是使用ng-repeat它不会显示一张图像。

我怀疑我的问题是:

  1. 我的 ng-repeat 有什么问题吗?
  2. 图像实际上是否正确存储在数组内?

HTML

 <button class="button button-full button-assertive" ng-click="takePhoto()">
    Take Photo
    </button>
    <img ng-show="imgURI !== undefined" ng-src="{{imgURI}}" style="text-align: center">
<ion-item class="item item-assertive">Test array</ion-item>
 <div ng-repeat="x in array">
     <img ng-src="{{x.imgURI}}">
 </div> center">

Javascript

  $scope.takePhoto = function () {
              var options = {
                quality: 75,
                destinationType: Camera.DestinationType.DATA_URL,
                sourceType: Camera.PictureSourceType.CAMERA,
                allowEdit: true,
                encodingType: Camera.EncodingType.JPEG,
                targetWidth: 300,
                targetHeight: 300,
                popoverOptions: CameraPopoverOptions,
                saveToPhotoAlbum: false
            };

                $scope.array = [];

                $cordovaCamera.getPicture(options).then(function (imageData) {
                    $scope.imgURI = "data:image/jpeg;base64," + imageData;
                    $scope.imgURI = array;
                }, function (err) {
                    // An error occured. Show a message to the user
                });
            }

最佳答案

您正在将 imageUri 设置为数组的值。

$scope.imgURI = ar;

我想你想像这样对数组进行推送:

$scope.array.push($scope.imgURI);

关于javascript - 将图像插入数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37674782/

相关文章:

php - 如何检索我们在谷歌地图中标记的最近的商店?

javascript - 用于选择 td 标签的全选按钮

javascript - 为什么一个行内 block 元素比其他元素略高

php - 帮我从多维 PHP 数组中获取一个值

javascript - For 循环内的 Loopback 回调

javascript - 大 div 褪色的一些问题

java - Eclipse 给出关于不返回整数的错误

java - 如何将 "add parsed string that used filter"转换为字符串 ArrayList

javascript - 合并来自两个http请求的AngularJS对象

html - 纯 html5 与 jquery 移动/angularjs