Loopback получить данные от одного модуля к другому - PullRequest
0 голосов
/ 08 апреля 2019

Я использую 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 голосов
/ 08 апреля 2019

позвоните вашей другой модели сюда. Насколько я понимаю, вы пытаетесь вставить имя файла. поэтому я изменил твой код.

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

надеюсь, что это поможет

...