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

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

问题描述

我在这里遇到一个奇怪的问题.我有一个使用 Parse.com 构建的项目作为后端(在建立与数据库的连接时使用 cloudcode 来验证某些事情).一切正常.

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 之前之前在 iOS 代码中定义的每个键.请注意,使用我的个人帐户一切正常...

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"而不是最新",将其上传到 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 - containing cloud code files

• 配置 - 包含 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天全站免登陆