[英]Parse cloud function define
My question is about the first line of parse cloud function. 我的问题是关于解析云函数的第一行。 for example, this function is copy from parse docs:
例如,此函数是从解析文档中复制的:
Parse.Cloud.beforeSave(Parse.User, function(request, response) {
if (!request.object.get("email")) {
response.error("email is required for signup");
} else {
response.success();
}
});
The Parse.User is a parse predefined class. Parse.User是一个解析预定义类。 Does that mean this cloud function will be automatically executed when saving a object in this class?
这是否意味着在此类中保存对象时将自动执行此云函数?
Another question is also about the class. 关于班级也有另一个问题。 here are two examples of parse cloud function from parse example app Anypic and Parse docs:
这是来自解析示例应用程序Anypic和Parse docs的解析云函数的两个示例:
Parse.Cloud.beforeSave('Activity', function(request, response) {
var currentUser = request.user;
var objectUser = request.object.get('fromUser');
if(!currentUser || !objectUser) {
response.error('An Activity should have a valid fromUser.');
} else if (currentUser.id === objectUser.id) {
response.success();
} else {
response.error('Cannot set fromUser on Activity to a user other than the current user.');
}
});
Parse.Cloud.beforeSave("Review", function(request, response) {
if (request.object.get("stars") < 1) {
response.error("you cannot give less than one star");
} else if (request.object.get("stars") > 5) {
response.error("you cannot give more than five stars");
} else {
response.success();
}
});
What's the difference between these two cloud function in the first line: the Activity is quoted in single quotation marks but the Review is quoted in double quotation marks. 第一行中这两个云函数之间的区别是:活动用单引号引起来,而审阅用双引号引起来。 Are they all stands for some parse subclass or something else?
它们都是代表解析子类还是其他东西?
To answer your original question: Yes, the function with signature: 要回答您的原始问题:是的,带签名的功能:
Parse.Cloud.beforeSave(Parse.User, function(request, response)
will be executed before every Parse.User class object is saved. 将在保存每个Parse.User类对象之前执行。
To answer your next question, those two examples are equivalent. 为了回答您的下一个问题,这两个示例是等效的。
http://stackoverflow.com/questions/242813/when-to-use-double-or-single-quotes-in-javascript
They do pre-save stuff for the Activity and Review classes respectively. 它们分别为Activity和Review类预先保存内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.