环回将数据从一个模块发送到另一个

时间:2019-04-08 07:38:05

标签: node.js loopbackjs strongloop loopback

我正在使用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: 'john@gmail.com', 
            from: 'noreply@gmail.com', 
            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) {

};

1 个答案:

答案 0 :(得分:0)

call your other model over here. as per my understanding, you try to insert file name. so I modified your code.

'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: 'john@gmail.com', 
        from: 'noreply@gmail.com', 
        subject: 'Career Form', 
        html: '<em>Hi,</em>'

        },
       function(err, mail) { 
            // console.log(context.result.email)
        console.log('email sent!'); 
        console.log(err); 
    }); 
});

hope this help