Javascript 将图像推入阵列
我想拍摄不同物品的照片或一件物品的多张照片,但我很难弄清楚如何将图像推送到阵列中 从第一行开始显示单个图像:Javascript 将图像推入阵列,javascript,arrays,angularjs,ionic-framework,Javascript,Arrays,Angularjs,Ionic Framework,我想拍摄不同物品的照片或一件物品的多张照片,但我很难弄清楚如何将图像推送到阵列中 从第一行开始显示单个图像: <img ng-show="imgURI !== undefined" ng-src="{{imgURI}}" style="text-align: center"> Javascript $scope.takePhoto = function () { var options = { quality: 75,
<img ng-show="imgURI !== undefined" ng-src="{{imgURI}}" style="text-align: 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);
您正在将imageUri设置为数组的值
$scope.imgURI = ar;
我想你应该像这样对阵列进行推送:
$scope.array.push($scope.imgURI);
为了测试这段代码,我在takePhoto函数之外创建了一个数组,并在其中推送图像
$scope.array = [];
$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
};
$cordovaCamera.getPicture(options).then(function (imageData) {
$scope.array.push("data:image/jpeg;base64," + imageData);
}, function (err) {
// An error occured. Show a message to the user
});
}
您的html应该如下所示
<div ng-repeat="x in array"> <img ng-show="x !== undefined" ng-src="{{x}}"> </div>`
`
测试这段代码,我在takePhoto函数之外创建了一个数组,并在其中推送图像
$scope.array = [];
$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
};
$cordovaCamera.getPicture(options).then(function (imageData) {
$scope.array.push("data:image/jpeg;base64," + imageData);
}, function (err) {
// An error occured. Show a message to the user
});
}
您的html应该如下所示
<div ng-repeat="x in array"> <img ng-show="x !== undefined" ng-src="{{x}}"> </div>`
`
什么是ar?在您的标记(x in ar
)和代码($scope.imageUri=ar
)中,很抱歉,我忘了更改,现在将进行编辑@Jamiecar什么是ar
?在您的标记(x in ar
)和代码($scope.imageUri=ar
)中,很抱歉,我忘了更改,现在将进行编辑@Jamieck需要补充一点:由于数组将URI存储为字符串,而不是包装在对象中,ng repeat
中的图像应该直接访问x
而不是x.imgURI
我在测试它时遇到问题,因为api只在我的手机上工作,ng repeat没有显示任何内容。只需添加一件事:由于数组将URI存储为字符串,而不是包装在对象中,ng repeat
中的图像应该直接访问x
而不是x。imgURI
我测试它时遇到问题,因为api只在我的手机上工作,ng repeat没有显示任何内容。调用单个图像时,您的编码工作正常,但正如我的另一个问题所述,我正在努力显示多个图像。这是我的想法,但不起作用,有什么想法吗`调用单个图像时,您的编码工作正常,但正如我的另一个问题所述,我很难显示多个图像。这是我的想法,但不起作用,有什么想法吗`