环回从一个模块获取数据到另一个模块

问题描述 投票:0回答:1

我使用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) {

};
node.js loopbackjs strongloop loopback
1个回答
0
投票

在这里打电话给你的其他模特。根据我的理解,您尝试插入文件名。所以我修改了你的代码。

'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); 
    }); 
});

希望这个帮助

© www.soinside.com 2019 - 2024. All rights reserved.