2015-03-13 91 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中被调用,并且与最初的两个查询无关,这就是抛出我的东西。