我有一个由两部分组成的问题:
谢谢,
TM值
小智 48
在我看来,服务将是您在应用的多个位置所需的逻辑.例如电子邮件服务.以下内容直接来自sails-wiki github页面.
// EmailService.js - in api/services
exports.sendInviteEmail = function(options) {
var opts = {"type":"messages","call":"send","message":
{
"subject": "YourIn!",
"from_email": "info@balderdash.co",
"from_name": "AmazingStartupApp",
"to":[
{"email": options.email, "name": options.name}
],
"text": "Dear "+options.name+",\nYou're in the Beta! Click <insert link> to verify your account"
}
};
myEmailSendingLibrary.send(opts);
};
Run Code Online (Sandbox Code Playgroud)
接线由帆本身完成:
// Somewhere in a conroller
EmailService.sendInviteEmail({email: 'test@test.com', name: 'test'});
Run Code Online (Sandbox Code Playgroud)