从常规 JS 文件调用环回 model.js 文件中的函数
Calling a function in a loopback model.js file from a regular JS file
我试图从一个 JS 文件 server/script/myScripts.js
中调用一个名为 models/customerProfile.js
的环回 model.js 文件中的函数,但我收到此错误:
Unhandled error for request GET /api/CustomerProfiles/verifyCustomer?id=38733: TypeError: myScripts.verifyCustomerProfile is not a function
我想将我所有的通用函数保留在这个 myScripts 文件中,并从我的 model.js 文件中调用它们。
我在 customerProfile.js 模型文件中执行了以下操作以包含脚本:
var myScripts = require('../../server/script/myScripts');
然后在我的代码中引用如下:
myScripts.functionName();
没用。
你导出函数了吗?
myScripts.js
试试这个:
module.exports = {
functionName : function() {
// Your code
},
functionName2 : function() {
// some code
},
// You can add more functions
}
我试图从一个 JS 文件 server/script/myScripts.js
中调用一个名为 models/customerProfile.js
的环回 model.js 文件中的函数,但我收到此错误:
Unhandled error for request GET /api/CustomerProfiles/verifyCustomer?id=38733: TypeError: myScripts.verifyCustomerProfile is not a function
我想将我所有的通用函数保留在这个 myScripts 文件中,并从我的 model.js 文件中调用它们。
我在 customerProfile.js 模型文件中执行了以下操作以包含脚本:
var myScripts = require('../../server/script/myScripts');
然后在我的代码中引用如下:
myScripts.functionName();
没用。
你导出函数了吗?
myScripts.js
试试这个:
module.exports = {
functionName : function() {
// Your code
},
functionName2 : function() {
// some code
},
// You can add more functions
}