[英]Parse Cloud Code Iterating Results Issue
I'm using parse and trying to make a cloud code query to handle this: 我正在使用解析并尝试进行云代码查询来处理此问题:
I want to query a table and then iterate over all the results and check if column1 > column2. 我想查询一个表,然后遍历所有结果并检查column1> column2。 I'm not sure there is a way to do that with query constraints so I am doing a for loop over the results. 我不确定是否可以使用查询约束来做到这一点,所以我正在对结果进行for循环。
However my issue is when I return goodRides in my iOS app I get this error: 但是我的问题是,当我在iOS应用中返回goodRides时,出现此错误:
"JSON text did not start with array or object and option to allow fragments not set."
If I return results without iterating and parsing which ones I want that works fine so I'm not sure exactly what I'm doing wrong in my loop iteration. 如果我返回的结果没有迭代和解析我想要的结果,那将很好地工作,所以我不确定在循环迭代中我到底做错了什么。
Here is my code: 这是我的代码:
q.find()
.then(results => {
var goodRides;
for(var i = 0; i < results.length; i++)
{
if(results[i].get("availableSeats") > results[i].get("occupiedSeats")){
goodRides.push(results[i]);
}
}
return goodRides;
})
.then(rides => {
res.success(rides);
})
.catch(function (err){
res.log.error("Error");
});
My issue is when I try to push(results[i] onto the goodRides variable everything breaks. How can I iterate the results and extract only the indices I want? 我的问题是,当我尝试将(results [i]推送到goodRides变量时,一切都中断了。如何迭代结果并仅提取所需的索引?
Here's how I would write this: 这是我的写法:
q.find()
.then(results => Promise.resolve(
results.filter((result) => result.get('availableSeats') > result.get('occupiedSeats'))
))
.then(rides => res.success(rides))
.catch(err => res.error(err))
goodRides
必须初始化为数组才能推送到它。
var goodRides = [];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.