我确信这是一个简单的方法,但我无法让链式函数在 Parse.com 的 Cloud Code 中工作。我知道这是可能的——所以这可能是对我的 javascript n00bness 的控诉。;>
下面是一个简单的测试函数链,它显示了我认为它应该如何工作 - 但事实并非如此。在response.error
事件中,我似乎得到了错误,但在成功时我得到:
{"code":141,"error":"success/error was not called"}
以下是测试功能:
Parse.Cloud.define("initialFunction", function(request, response) {
var player = request.params.player;
Parse.Cloud.run("chainedFunction",{ player: player.id },{
sucess: function(results) {
response.success(results);
},
error: function(results, error) {
response.error(errorMessageMaker("running chained function",error));
}
});
});
Parse.Cloud.define("chainedFunction", function(request, response) {
var player = Parse.Object.extend("User");
var findPlayer = new Parse.Query(player);
findPlayer.get(request.params.player, {
success: function(player) {
var games = player.relation("games");
games.query().find({
success: function(games) {
response.success(games);
},
error: function(players, error) {
response.error(errorMessageMaker("finding games",error));
}
});
},
error: function(player,error) {
response.error(errorMessageMaker("finding player",error));
}
});
});
..这是我对该函数的初始调用,以供参考(尽管我确信这不是问题):
curl -X POST \
-H "X-Parse-Application-Id: <id>" \
-H "X-Parse-REST-API-Key: <id>" \
-H "Content-Type: application/json" \
-d '{"player":"<id>"}' \
https://api.parse.com/1/functions/initialFunction