【发布时间】:2014-07-13 13:50:57
【问题描述】:
我想要完成的是,当我调用这个云函数 (deploy) 时,它会首先删除 toClass 中的所有数据,然后遍历 fromClass 中的对象,将它们复制并保存到 @987654324 @。当它保存一个对象时,它也会从fromClass 中删除它。简而言之,将对象从类移动到另一个。在客户端调用这个函数
[PFCloud callFunctionInBackground:@"deploy" withParameters:@{@"toClass": kTilrClassUpdates, @"fromClass": kTilrClassPrototypeUpdates} block:^(id object, NSError *error) {
if (error) {
[self failed];
} else {
[self succeeded];
}
}];
会将此错误信息打印到客户端日志:Error: undefined (Code: 141, Version: 1.2.19)
这是 Parse Cloud 的代码:
Parse.Cloud.define("deploy", function(request, response) {
var query = new Parse.Query(request.params.toClass);
query.find({
success: function(results) {
for (var i = 0; i < results.length; ++i) {
console.log(results[i]);
results[i].destroy({
success: function(object) {
},
error: function(object, error) {
response.error(error);
}
});
}
},
error: function() {
response.error(error);
}
});
var query2 = new Parse.Query(request.params.fromClass);
query2.find({
success: function(results) {
for (var index = 0; index < results.length; ++index) {
var UpdateInfoClass = Parse.Object.extend(request.params.toClass);
var updateInfo = new UpdateInfoClass();
for (var k in results[index]) {
updateInfo.set(k, results[index][k]);
}
console.log(updateInfo);
updateInfo.save(null, {
success: function(updateInfo) {
results[index].destroy();
if (index == results.length - 1) {
response.success();
}
},
error: function(updateInfo, error) {
response.error(error);
}
});
}
},
error: function() {
response.error(error);
}
});
});
我真的不太了解 JavaScript,所以这可能是一个非常简单的错误。
【问题讨论】:
标签: javascript ios parse-platform