简体   繁体   English

解析request.object.get(“KEY”)总是返回undefined

[英]Parse request.object.get(“KEY”) always returns undefined

I have a strange problem over here. 我这边有一个奇怪的问题。 I have a project built with Parse.com as a backend (using cloudcode to verify some things when a connection to the database is made). 我有一个使用Parse.com构建的项目作为后端(使用云代码来验证与数据库建立连接时的某些事情)。 Everything works just as it should do. 一切都按照应有的方式运作。

But here comes the problem. 但问题来了。 Another developer reported to me that there is something wrong because he is getting 'undefined' every time he tries to call request.object.get('KEY') in CloudCode. 另一位开发人员向我报告说有一些错误,因为他每次尝试在CloudCode中调用request.object.get('KEY')时都会“未定义”。 This developer uses the exact same codebase as I do. 这个开发人员使用与我完全相同的代码库。

So I decided to have a look at it. 所以我决定看看它。 While with my Parse account, every application works fine (even newly created ones), with the Parse account of the other developer, not a single new application we created seems to work with the exact same code. 使用我的Parse帐户,每个应用程序都可以正常工作(甚至是新创建的应用程序),使用其他开发人员的Parse帐户,而不是我们创建的单个新应用程序似乎使用完全相同的代码。 And it is getting even stranger - creating a completely new Parse account and a new application produces the same errors while my personal account and applications continue to work fine. 它变得更加陌生 - 创建一个全新的Parse帐户和一个新的应用程序产生相同的错误,而我的个人帐户和应用程序继续正常工作。

So what is the problem? 那么问题是什么? We are using CloudCode, and here is sample code (in javascript) of a beforeSave method: 我们正在使用CloudCode,这里是beforeSave方法的示例代码(在javascript中):

Parse.Cloud.beforeSave('Activity', function(request, response) {
   var currentUser = request.user;
   var objectUser = request.object.get('fromUser');
   if(!currentUser || !objectUser) {
     response.error('An Activity should have a valid fromUser.');
   } else {
     response.success();
   }
});

And every time request.object.get('KEY') returns undefined , for every key I previously defined in the iOS code before uploading the PFObject . 每次request.object.get('KEY')返回undefined ,对于我之前在iOS代码中定义的每个键,在上传PFObject之前。 Note that with my personal account everything is fine... 请注意,使用我的个人帐户一切都很好......

I have already seen this thread, however deleting ACL's didn't do the trick. 我已经看过这个帖子,但是删除ACL并没有做到这一点。 request.object.get() stays undefined while request.user is defined for every tested Parse account except mine. request.object.get()保持未定义,而request.user是为除了我的每个测试的Parse帐户定义的。

EDIT 1 编辑1

I also had a look at the activity object just before it is uploaded, and there all the fields are properly set. 我还在上传活动对象之前查看了活动对象,并且所有字段都已正确设置。

EDIT 2 编辑2

After removing the cloud code completely, the objects are correctly being uploaded to Parse, with all the fields being the way they were set via the iOS client. 完全删除云代码后,对象被正确上传到Parse,所有字段都是通过iOS客户端设置的方式。 So it seems that something is wrong with Parse's cloud code, but as soon as an object passes through cloud code, it looses all its fields. 因此,Parse的云代码似乎有问题,但是一旦对象通过云代码,它就会丢失其所有字段。

Finally I was able to solve this. 最后我能够解决这个问题。 This is definitely a bug in Parse's Javascript SDK. 这绝对是Parse的Javascript SDK中的一个错误。 I changed the Javascript SDK version in the global.json back to version "1.4.2" instead of "latest", uploaded this to the cloudcode folder and everything went back to normal. 我将global.json中的Javascript SDK版本更改回版本“1.4.2”而不是“latest”,将其上传到cloudcode文件夹,一切都恢复正常。

You can also test other versions, maybe v1.5.0 is working too, but as soon as I found out v1.4.2 worked fine, I didn't try out more recent versions. 你也可以测试其他版本,也许v1.5.0也在工作,但是一旦我发现v1.4.2工作正常,我没有尝试更新的版本。

EDIT 编辑

So, I discovered, that Parse must have changed something in their command line tool. 所以,我发现,Parse必须在命令行工具中改变一些东西。 It seems that the global.json file isn't there anymore if you create your CloudCode folder with the most recent version of their command line tool. 如果您使用最新版本的命令行工具创建CloudCode文件夹,似乎global.json文件不再存在。 However, you can manually create it and upload the complete folder to your Parse app. 但是,您可以手动创建它并将完整文件夹上载到Parse应用程序。

This is how my CloudCode folder looks like, just for example: CloudCode folder contains three subfolders 这就是我的CloudCode文件夹的样子,例如:CloudCode文件夹包含三个子文件夹

• cloud - containing cloud code files •云 - 包含云代码文件

• config - containing the global.json file •config - 包含global.json文件

• public - containing the index.html file •public - 包含index.html文件

The global.json file contains these lines of code: global.json文件包含以下代码行:

{
  "global": {
    "parseVersion": "1.4.2"
  },
  "applications": {
    "YOUR_PARSE_APPS_NAME": {
      "applicationId": "YOUR_APP_ID",
      "masterKey": "YOUR_APP_MASTER_KEY"
    },
    "_default": {
      "link": "YOUR_PARSE_APPS_NAME"
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM