2015-03-13 87 views
0

我正在使用Parse作爲後端的移動應用程序,並且我對find函數有問題。以下列格式運行查找功能時:解析查詢查找方法返回對象不是數組

var = firstQuery = (new Parse.Query("MyParseObject")) 
    .find(), 
    secondQuery = (new Parse.Query("OtherParseObject")).get(id) 

// there is only one object that firstQuery can find 
Parse.Promise.when(firstQuery, secondQuery) 
    .then(function (query1res, query2res) { 
    // query1res should return only one result wrapped in an array, 
    // instead query1res is an object without a get method 

    query1res.forEach (function (res) { 
    // this fails: cannot get .length of undefined 
    }) 
    // ... do stuff with the returned data 


    }) 

有什麼我失蹤?我相信這個曾經工作過,但現在不行。

由於Parse的工作方式,要正確調試這個問題是很困難的,但是他們的文檔概述了這應該返回一個數組,但是它現在還沒有。

感謝您的幫助。

回答

0

基礎上Parse docs,它看起來像Parse.Promise.when預計數組,雖然基於this support thread,結果將作爲單獨的參數傳遞給then處理程序。試試這個:

Parse.Promise.when([firstQuery, secondQuery]) 
.then(function (query1res, query2res) { 

    // use query1res and query2res 
}); 
0

原來,這歸功於代碼中更深層的函數,它需要返回一個承諾來鏈接。在添加這個代碼後,代碼非常開心。返回promise的函數在forEach中被調用,並且與最初的兩個查詢無關,這就是拋出我的東西。