我需要更新存储在类中的多个对象的特定字段。我可以从客户端做到这一点,但我不喜欢它处理额外带宽的想法。如何更新和保存我在Cloud Code查询中迭代过的对象?基本上,什么是以下Swift方法的JS等价物?
var query = PFQuery(className:"GameScore")
query.whereKey("playerName", equalTo:"Sean Plott")
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
// The find succeeded.
println("Successfully retrieved \(objects!.count) scores.")
// Do something with the found objects
if let objects = objects as? [PFObject] {
for object in objects {
// Update object here
}
// Save your changes to ALL objects
PFObject.saveAllInBackground()
}
} else {
// Log details of the failure
println("Error: \(error!) \(error!.userInfo!)")
}
}
答案 0 :(得分:2)
我不确定你到底想要做什么,但也许这就是你要找的东西:
Parse.Cloud.define("updateScores", function(request, response) {
var query = new Parse.Query("GameScore");
query.equalTo("playerName", "Sean Plott");
query.each(function (object) {
// Do something with object
object.save();
}).then(function (success) {
request.success("OK");
}, function(err) {
request.error(err);
});
});