解析云代码查询不断变为未定义

时间:2015-12-26 08:49:25

标签: 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(“post id is”+ 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)

1 个答案:

答案 0 :(得分:3)

尝试如下。可能会帮助它。

results[0].get("installationId")

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