我使用loopback3作为文件存储attachment.js,我有persistedmodel career.js用于存储数据。现在我想在career.js中获取文件名。这该怎么做。
career.js
'use strict';
const app = require('../../server/server');
module.exports = function(Career) {
Career.afterRemote('create', function(context, remoteMethodOutput, next) {
next();
// console.log(context.result)
Career.app.models.Email.send({
to: '[email protected]',
from: '[email protected]',
subject: 'Career Form',
html: '<em>Hi,</em>'
},
function(err, mail) {
// console.log(context.result.email)
console.log('email sent!');
console.log(err);
});
});
attachment.js
'use strict';
module.exports = function(Attachment) {
};
在这里打电话给你的其他模特。根据我的理解,您尝试插入文件名。所以我修改了你的代码。
'use strict';
const app = require('../../server/server');
module.exports = function(Career) {
Career.afterRemote('create', function(context, remoteMethodOutput, next) {
var companyprofile=app.models."yourmodel" // model name from where you want to insert file name
companyprofile.create({cust_cmp_profile:context.args.data.cust_cmp_profile},
function(err) {
if (err){
next(err)
}
else{
next()
}
});
// console.log(context.result)
Career.app.models.Email.send({
to: '[email protected]',
from: '[email protected]',
subject: 'Career Form',
html: '<em>Hi,</em>'
},
function(err, mail) {
// console.log(context.result.email)
console.log('email sent!');
console.log(err);
});
});
希望这个帮助