【问题标题】:Calling a function in a loopback model.js file from a regular JS file从常规 JS 文件调用环回 model.js 文件中的函数
【发布时间】:2017-10-16 22:56:46
【问题描述】:

我正在尝试从 JS 文件 server/script/myScripts.js 调用名为 models/customerProfile.js 的 loopback model.js 文件中的函数,但出现此错误:

请求 GET /api/CustomerProfiles/verifyCustomer?id=38733 的未处理错误:TypeError:myScripts.verifyCustomerProfile 不是函数

我想将我所有的通用函数保存在这个 myScripts 文件中,并从我的 model.js 文件中调用它们。

我在 customerProfile.js 模型文件中执行了以下操作以包含脚本:

var myScripts = require('../../server/script/myScripts');

然后在我的代码中我引用它如下:

myScripts.functionName();

它不起作用。

【问题讨论】:

标签: javascript loopbackjs loopback


【解决方案1】:

你导出你的函数了吗?

myScripts.js

试试这个:

module.exports = {

functionName : function() {
 // Your code
},

functionName2 : function() {
 // some code
},

// You can add more functions

}

【讨论】:

  • module.exports = function (app) { verifyCustomerProfile = function(id){ console.log("我在这里");这是 myScripts.js 文件中的函数示例。我正在尝试在我的 customerProfile.js 模型中使用此功能。
猜你喜欢
  • 2012-10-14
  • 1970-01-01
  • 2018-08-14
  • 1970-01-01
  • 1970-01-01
  • 2016-06-21
  • 1970-01-01
  • 2019-01-23
  • 1970-01-01
相关资源
最近更新 更多