文件Parse.com阵列 [英] Parse.com array of files

查看:102
本文介绍了文件Parse.com阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上传图片到Parse.com和成功的响应它返回的文件名(生成)和文件的URL。它这是罚款单协会但是我的一个类需要有很多的文件一个条目。

I am uploading images to Parse.com and in a successful response it returns the filename (generated) and the file URL. It this is fine for single association however one of my classes needs to have many files to one entry.

目前试图让指针 / 文件引用所以他们在数据浏览器蓝色显示的数组纽扣。的问题是,它不创建它只是引发对象到数组,因为它是这些蓝钮。

Currently trying to make an array of Pointers / File references so it they show in the data browser as blue buttons. The problem is that it does not create these blue buttons it just throws the object into the array as it is.

    $scope.saveCreatedExercise = function(exercise) {
        imageStore = []
        for (var i = 0; i < exercise.images.length; i++) {

            var data = {
                "__type": "File",
                "name": exercise.images[i]._name
            }
            imageStore.push(data);
        };

        ParseFactory.provider('ClientExercises/').create({
            exerciseDescription: exercise.exerciseDescription,
            exerciseName: exercise.exerciseName,
            user: {
                "__type": "Pointer",
                "className": "_User",
                "objectId": Parse.User.current().id
            },
            images: imageStore

        }).success(function(data) {
            $state.go('app.exercises', {
                loadProgramme: data.objectId
            });
        }).error(function(response) {
            errorFactory.checkError(response);
        });

    } 

这甚至可能实现?

Is this even possible to achieve?

我的问题的症结是,我想在我的类中的一个条目被关联到多个文件。

The crux of my problem is that I want one entry in my class to be associated to many files.

推荐答案

我有万一别人工作解决方案遇到这个问题。这种方法的重要性在于,不保存实际解析文件对象的引用,当您使用的设置做一个文件的清理,所有引用的文件将被删除。这种方法被清除保存这些文件。

I've got a working solution in case anyone else comes across this issue. The importance of this approach is that without saving the actual parse file object reference, when you use the settings to do a file clean-up, all of your referenced files will be deleted. This method keeps these files from being purged

我使用angularjs和解析在我的JavaScript实现SDK。我是有这个问题是一个JavaScript错误未捕获类型错误:转换圆形结构,以JSON。在加入ParseFile对象的父对象数组场的那一刻

I'm using angularjs and the parse javascript sdk in my implementation. The issue that I was having was a javascript error "Uncaught TypeError: Converting circular structure to JSON" at the moment of adding the ParseFile object to the parent object array field.

角V1.4.4,解析JS V1.5

Angular v1.4.4, Parse JS v1.5

var parseObject = {{ existing parse object }}
var files = {{ existing array of files base64 encoded }}
var parseFiles = [];
var promises = [];

// loop through the files so first save them to parse cloud 
// (in my case these files were uploaded via ng-file-upload)
angular.forEach(files, function(file,i){
  parseFiles[i] = new Parse.File(file.name,{
    base64: file.dataUrl
  });
  promises.push(parseFiles[i].save());
});

// actually save the files in one batch process of promises
Parse.Promise.when(promises).then(function(){
  // success callback says all files are saved, now lets add them to the parent
  angular.forEach(parseFiles, function(parseFile,i){
    delete parseFile._previousSave; //--> fix circular json error
    parseObject.addUnique('images',parseFile); // could alternatively use .add()
  });
  // now save the parent with the references to the files
  return parseListing.save();
}).then(function(){
  successCallback();
},function(error) {
  errorCallback();
});

这篇关于文件Parse.com阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆