使用承諾的快速雲代碼示例。我在那裏有一些文檔,我希望你可以關注。如果您需要更多幫助,請告訴我。
Parse.Cloud.define("getUserId", function(request, response)
{
//Example where an objectId is passed to a cloud function.
var id = request.params.objectId;
//When getUser(id) is called a promise is returned. Notice the .then this means that once the promise is fulfilled it will continue. See getUser() function below.
getUser(id).then
(
//When the promise is fulfilled function(user) fires, and now we have our USER!
function(user)
{
response.success(user);
}
,
function(error)
{
response.error(error);
}
);
});
function getUser(userId)
{
Parse.Cloud.useMasterKey();
var userQuery = new Parse.Query(Parse.User);
userQuery.equalTo("objectId", userId);
//Here you aren't directly returning a user, but you are returning a function that will sometime in the future return a user. This is considered a promise.
return userQuery.first
({
success: function(userRetrieved)
{
//When the success method fires and you return userRetrieved you fulfill the above promise, and the userRetrieved continues up the chain.
return userRetrieved;
},
error: function(error)
{
return error;
}
});
};
不知道query.first()方法。感謝你! – 2015-09-01 22:37:02
Parse.Cloud.useMasterKey();已在Parse Server版本2.3.0(2016年12月7日)中棄用。從那個版本開始,它是一個無操作(它什麼都不做)。您現在應該將{useMasterKey:true}可選參數插入到需要在代碼中重寫ACL或CLP的每個方法中。 – alvaro 2017-06-01 00:27:45