简体   繁体   English

使用loopback-datasource-juggler获取环回模型

[英]Get loopback models using loopback-datasource-juggler

Is there any other way other than getting the loopback model by using app object in a custom js file? 除了通过在自定义js文件中使用app对象获取环回模型之外还有其他方法吗?

Found that requiring server.js file is possible. 发现需要server.js文件是可能的。

var app = require('/server/server');

But the problem is that each time when we are using app object, its restarting, since each time server is getting started. 但问题是每次我们使用app对象时,都会重新启动,因为每次服务器都开始使用。

you can use it this way, for example in boot scripts you have a custom file and you can pass the app object as: 你可以这样使用它,例如在启动脚本中你有一个自定义文件,你可以将app对象传递为:

'use strict';

module.exports = function(app) {
  app.models.User.find({}, (err, users) => {
    console.log('USERS:', users);
  });
};

Or where do you put your custom js file and how do you include it? 或者你在哪里放置自定义js文件,你如何包含它?

Your controller should look like this: 您的控制器应如下所示:

customer.js customer.js

 module.exports = function (Customer) { let app // Use app in your remote methods or hooks Customer.on('attached', function (a) { app = a }) } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM