2015-12-26 73 views
1

我是一個快速的初學者開發人員,沒有真正的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( 「後ID爲」 +帖子ID)

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) 
+0

請提供完整的雲碼功能。 – Moonwalkr

回答

3

嘗試像下面。可能會幫助它。

results[0].get("installationId") 

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