[英]Parse Query find method returns object not array
我正在使用將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的工作方式,很難正確調試此問題,但他們的文檔概述了此操作應返回一個數組,但此時不返回。
謝謝你的幫助。
基於Parse docs ,看起來像Parse.Promise.when
需要一個數組,盡管基於此支持線程 ,結果仍將作為單獨的參數傳遞給then
處理程序。 試試看:
Parse.Promise.when([firstQuery, secondQuery])
.then(function (query1res, query2res) {
// use query1res and query2res
});
事實證明,這取決於代碼中更深層的功能,該功能需要返回一個承諾以將其鏈接出去。 添加此代碼后,代碼就足夠高興了。 需要返回promise的函數在forEach中被調用,與最初的兩個查詢無關,這就是給我扔的東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.