2017-06-30 50 views
0
{ 
    "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' 
      } 
     } 
    ); 
}; 

我已經安裝回送連接器的PostgreSQL &生成的模型,但是當我試圖通過編寫自定義的API收到錯誤。

回答

1

module.exports之前宣佈

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

這是,你是在共同文件夾模型目錄的假設。

然後而是採用Projects.app.datasource使用app.datasource

+0

感謝@itssajan現在的工作。 – Nayank

+0

如果你能接受我的答案,這將是有幫助的。 – itssajan

相關問題