无法读取未定义的 属性 'connector'
Cannot read property 'connector' of undefined
{
"error": {
"statusCode": 500,
"name": "TypeError",
"message": "Cannot read property 'connector' of undefined",
"stack": "TypeError: Cannot read property 'connector' of undefined\n at Function.Projects.getProjectData (F:\SanWork\AngularWorkSpace\jobMngt\common\models\projects.js:7:44)\n at SharedMethod.invoke (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\strong-remoting\lib\shared-method.js:263:25)\n at HttpContext.invoke (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\strong-remoting\lib\http-context.js:389:12)\n at phaseInvoke (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\strong-remoting\lib\remote-objects.js:654:9)\n at runHandler (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\lib\phase.js:135:5)\n at iterate (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\node_modules\async\lib\async.js:146:13)\n at Object.async.eachSeries (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\node_modules\async\lib\async.js:162:9)\n at runHandlers (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\lib\phase.js:144:13)\n at iterate (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\node_modules\async\lib\async.js:146:13)\n at F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\node_modules\async\lib\async.js:157:25\n at F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\node_modules\async\lib\async.js:154:25\n at execStack (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\strong-remoting\lib\remote-objects.js:493:7)\n at RemoteObjects.execHooks (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\strong-remoting\lib\remote-objects.js:497:10)\n at phaseBeforeInvoke (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\strong-remoting\lib\remote-objects.js:650:10)\n at runHandler (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\lib\phase.js:135:5)\n at iterate (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\node_modules\async\lib\async.js:146:13)"
}
}
使用此代码时出现此错误,我想知道导致错误的原因以及任何可能的修复方法。
型号代码:
'use strict';
module.exports = function(Projects) {
Projects.getProjectData = function(cb) {
var sql = 'select * from projects';
// call sql query from postreSQL
Projects.app.datasources.postgres.connector.query(sql, function(err, result) {
if (err) {
console.log('Error retrieving projects result ...');
console.log(err);
return cb(err);
}
cb(err, result[0].jsondata);
});
}
Projects.remoteMethod(
'getProjectData', {
returns: [{
type: 'string',
required: true,
root: true
}],
http: {
verb: 'get'
}
}
);
};
我已经安装了 loopback-connector-postgresql 并生成了模型,但是当我尝试编写自定义 api 时出现错误。
在 module.exports
声明之前
var app = require('../../server/server.js');
这是假设您位于公共文件夹的模型目录中。
然后使用 app.datasource
而不是 Projects.app.datasource
{
"error": {
"statusCode": 500,
"name": "TypeError",
"message": "Cannot read property 'connector' of undefined",
"stack": "TypeError: Cannot read property 'connector' of undefined\n at Function.Projects.getProjectData (F:\SanWork\AngularWorkSpace\jobMngt\common\models\projects.js:7:44)\n at SharedMethod.invoke (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\strong-remoting\lib\shared-method.js:263:25)\n at HttpContext.invoke (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\strong-remoting\lib\http-context.js:389:12)\n at phaseInvoke (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\strong-remoting\lib\remote-objects.js:654:9)\n at runHandler (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\lib\phase.js:135:5)\n at iterate (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\node_modules\async\lib\async.js:146:13)\n at Object.async.eachSeries (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\node_modules\async\lib\async.js:162:9)\n at runHandlers (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\lib\phase.js:144:13)\n at iterate (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\node_modules\async\lib\async.js:146:13)\n at F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\node_modules\async\lib\async.js:157:25\n at F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\node_modules\async\lib\async.js:154:25\n at execStack (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\strong-remoting\lib\remote-objects.js:493:7)\n at RemoteObjects.execHooks (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\strong-remoting\lib\remote-objects.js:497:10)\n at phaseBeforeInvoke (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\strong-remoting\lib\remote-objects.js:650:10)\n at runHandler (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\lib\phase.js:135:5)\n at iterate (F:\SanWork\AngularWorkSpace\jobMngt\node_modules\loopback-phase\node_modules\async\lib\async.js:146:13)"
}
}
使用此代码时出现此错误,我想知道导致错误的原因以及任何可能的修复方法。
型号代码:
'use strict';
module.exports = function(Projects) {
Projects.getProjectData = function(cb) {
var sql = 'select * from projects';
// call sql query from postreSQL
Projects.app.datasources.postgres.connector.query(sql, function(err, result) {
if (err) {
console.log('Error retrieving projects result ...');
console.log(err);
return cb(err);
}
cb(err, result[0].jsondata);
});
}
Projects.remoteMethod(
'getProjectData', {
returns: [{
type: 'string',
required: true,
root: true
}],
http: {
verb: 'get'
}
}
);
};
我已经安装了 loopback-connector-postgresql 并生成了模型,但是当我尝试编写自定义 api 时出现错误。
在 module.exports
声明之前
var app = require('../../server/server.js');
这是假设您位于公共文件夹的模型目录中。
然后使用 app.datasource
Projects.app.datasource