环回将数据从一个模块发送到另一个 [英] Loopback get data from one module to anothee

查看:92
本文介绍了环回将数据从一个模块发送到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用loopback3进行文件存储附件.js,并且使用了persistedmodel career.js来存储数据.现在,我想在career.js中获取文件名.该怎么做.

I am using loopback3 for file storage attachment.js and i have the persistedmodel career.js for storing the data. Now i want to fetch the file name in the career.js. how to do this.

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

attachment.js

'use strict';

module.exports = function(Attachment) {

};

推荐答案

在此处调用其他模型.据我了解,您尝试插入文件名.所以我修改了您的代码.

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

希望此帮助

这篇关于环回将数据从一个模块发送到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆