javascript - 解析云代码查询不断出现未定义

标签 javascript parse-platform

我是一个快速的初学者开发者,对 javascript 没有真正的经验。在过去的几个小时里,我一直在尝试使这个简单的查询正常工作,但无法弄清楚哪里出了问题。

我想获取名为“Post”的表中一行的“installationId”属性。所选行必须匹配特定的“id”。

我已经尝试了很多 var a 和 var b 的变体。像 results.get["installationId"] 或将查询更改为 find() 并执行 results[0].get["installationId"]。等等

这是我的代码,下面是我在 Parse Cloud 上记录的错误。

var postId = request.object.get('postId'); console.log("文章编号为"+ postId)

   query = new Parse.Query("Post");
   query.equalTo("postId", postId);

   query.first({
    success: function(results) {
       // results is an array of Parse.Object.

       var a = results //.get["installationId"]

       console.log("a query success from cloud code "+a)

       var b = results.object.get["installationId"]

       console.log("b query success from cloud code "+b)

       },

       error: function(error) {
       // error is an instance of Parse.Error.
       console.log("query error from cloud code")
       }
       });

这是日志中返回的内容:

I2015-12-26T08:01:26.373Z] - a query success from cloud code undefined
I2015-12-26T08:01:24.915Z] - post id is 1000
E2015-12-26T08:01:24.881Z] - v12 after_save triggered for AddVote:
  Input: {"object":{"UDID":"[confedential]","createdAt":"2015-12-26T08:01:24.876Z","objectId":"[confedential]","postId":"1000","updatedAt":"2015-12-26T08:01:24.876Z","userId":[confedential]}}
  Result: TypeError: Cannot read property 'get' of undefined
    at e.query.first.success (main.js:26:56)
    at e.<anonymous> (Parse.js:14:28823)
    at e.i (Parse.js:14:27528)
    at e.a.value (Parse.js:14:26888)
    at e.i (Parse.js:14:27655)
    at e.a.value (Parse.js:14:26888)
    at e.i (Parse.js:14:27655)
    at e.a.value (Parse.js:14:26888)
    at e.<anonymous> (Parse.js:14:27599)
    at e.i (Parse.js:14:27528)

最佳答案

像下面这样尝试。可能会有所帮助。

results[0].get("installationId")

var postObj = results[0].toJSON();
var subject = postObj.installationId;

关于javascript - 解析云代码查询不断出现未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34469824/

相关文章:

ios - 自定义单元格不显示 PFImageView?

javascript - 根据不同的按钮点击打开不同的iframe

ios - 更改密码 PFuser

javascript - 将一个 div 类放在 three.js 场景之上以创建一个 gui

javascript - 使用 javascript 根据选择显示/隐藏(切换)div 的显示

swift - 只加载前 10 个帖子,然后加载更多 - parse.com

python - 如何通过 Parse 检查推送通知发送是否已送达

java - 解析用户搜索

javascript - 逗号分隔的正则表达式

javascript - 注销后禁用浏览器 'Back' 按钮?