解析request.object.get(" KEY")始终返回undefined [英] Parse request.object.get("KEY") always returns undefined

查看:141
本文介绍了解析request.object.get(" KEY")始终返回undefined的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这边有一个奇怪的问题。我有一个使用Parse.com构建的项目作为后端(使用云代码来验证与数据库建立连接时的某些事情)。一切都可以正常运作。

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). Everything works just as it should do.

但问题出现了。另一位开发人员向我报告说,每次他试图在CloudCode中调用 request.object.get('KEY')时,都会出现未定义错误。这个开发人员使用与我完全相同的代码库。

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. This developer uses the exact same codebase as I do.

所以我决定看看它。使用我的Parse帐户,每个应用程序都可以正常工作(甚至是新创建的应用程序),使用其他开发人员的Parse帐户,而不是我们创建的单个新应用程序似乎使用完全相同的代码。它变得更加陌生 - 创建一个全新的Parse帐户和一个新的应用程序产生相同的错误,而我的个人帐户和应用程序继续正常工作。

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. 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.

那么问题是什么?我们正在使用CloudCode,这里是beforeSave方法的示例代码(在javascript中):

So what is the problem? We are using CloudCode, and here is sample code (in javascript) of a beforeSave method:

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();
   }
});

每次 request.object.get('KEY')返回 undefined ,然后再上传 PFObject
请注意,使用我的个人帐户,一切都很好......

And every time request.object.get('KEY') returns undefined, for every key I previously defined in the iOS code before uploading the PFObject. Note that with my personal account everything is fine...

我已经看过这个线程,但删除ACL没有做到这一点。 request.object.get()保持未定义,而 request.user 是为除了我的每个已测试的Parse帐户定义的。

I have already seen this thread, however deleting ACL's didn't do the trick. request.object.get() stays undefined while request.useris defined for every tested Parse account except mine.

编辑1

我还看过它之前的活动对象已上传,并且所有字段都已正确设置。

I also had a look at the activity object just before it is uploaded, and there all the fields are properly set.

编辑2

完全删除云代码后,对象被正确上传到Parse,所有字段都是通过iOS客户端设置的方式。因此,Parse的云代码似乎有问题,但是一旦对象通过云代码,它就会丢失所有字段。

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. 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的Javascript SDK中的一个错误。我将global.json中的Javascript SDK版本更改回版本1.4.2而不是latest,将其上传到cloudcode文件夹,一切都恢复正常。

Finally I was able to solve this. This is definitely a bug in Parse's 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.

你也可以测试其他版本,也许v1.5.0也在运行,但是一旦我发现v1.4.2工作正常,我没有尝试更新的版本。

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.

编辑

因此,我发现,Parse必须在其命令行工具中更改某些内容。如果您使用最新版本的命令行工具创建CloudCode文件夹,似乎不再存在global.json文件。但是,您可以手动创建它并将完整文件夹上传到Parse应用程序。

So, I discovered, that Parse must have changed something in their command line tool. 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. However, you can manually create it and upload the complete folder to your Parse app.

这就是我的CloudCode文件夹的样子,例如:
CloudCode文件夹包含三个子文件夹

This is how my CloudCode folder looks like, just for example: CloudCode folder contains three subfolders

•cloud - 包含云代码文件

• cloud - containing cloud code files

•config - 包含global.json文件

• config - containing the global.json file

•public - 包含index.html文件

• public - containing the index.html file

global.json文件包含以下代码行:

The global.json file contains these lines of code:

{
  "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"
    }
  }
}

这篇关于解析request.object.get(" KEY")始终返回undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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