[英]Parse Cloud Code Helper Function Not Working
Here is the parse javascript cloud code I wrote. 这是我编写的解析javascript云代码。 I want to find all objects in subclass "Example" having one like and then reset them as four.
我想在子类“示例”中找到所有具有相似对象的对象,然后将其重置为四个。 I have already established the Example class and Like column in the data browser.
我已经在数据浏览器中建立了Example类和Like列。 But the query didn't work and I can't figure out why.
但是查询不起作用,我不知道为什么。
function exampleFunction() {
var Example = Parse.Object.extend("Example");
var newObject = new Example();
newObject.save(); // until here, the function works, it continues creating new objects
var query = new Parse.Query(Example);
query.equalTo('Like',1);
query.find({
success:function(result){
for (var i = 0; i < result.length; i++) {
result[i].set('Like',4);
}
},
error:function(error){
}
})
}
Parse.Cloud.define("nice", function(request, response) {
exampleFunction();
response.success();
});
I use this period of code on iOS device to trigger the cloud function: 我在iOS设备上使用这段代码来触发云功能:
[PFCloud callFunctionInBackground:@"nice"
withParameters:@{}
block:^(NSString *result, NSError *error) {
if (!error) {
}
}];
A couple of possible issues.. 几个可能的问题。
then
function. then
函数。 See http://blog.parse.com/2013/01/29/whats-so-great-about-javascript-promises/ save
save
行 Try this below, noticing that the .success
should return a result if you NSLog(@"result %@",result)
from your objective-c. 请尝试以下操作,请注意,如果您从Objective-c获得
NSLog(@"result %@",result)
,则.success
应该返回结果。 Also, the error should be coming through now as well because of response.error(error)
另外,由于
response.error(error)
,错误现在也应该通过
var Example = Parse.Object.extend("Example");
function exampleFunction() {
var query = new Parse.Query(Example);
query.equalTo('Like',1);
return query.find().then(function(examplesLikedOnce){
var promises = [];
for (var i = 0; i < examplesLikedOnce.length; i++) {
var example = examplesLikedOnce[i];
var promise = example.save({Like:4});
promises.push(promise);
}
return Parse.Promise.when(promises).then(function(){
return examplesLikedOnce.length;
});
});
}
Parse.Cloud.define("nice", function(request, response) {
exampleFunction().then(function(numExamples){
response.success("The number of Example objects with 1 like: "+numExamples);
}, function(error){
response.error(error);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.