2017-02-28 3 views
0

いくつかのmysql関数で使用できるグローバル関数を使用しようとしましたが、問題はjsが ".then"が未定義であると言っています。 、これは構文エラーだけですか?Node.jsは未定義のプロパティ 'then'を読み取ることができません

static connectWidthCortex(){ 
    xdevapi.getSession({ 
     host: 'localhost', 
     port: 33060, 
     dbUser: 'admin', 
     dbPassword: 'xxxx' 
    }).then((session)=> { 
    return session.getSchema("cortex"); 
}); 
}; 

static createCollection(collname){ 
    this.connectWidthCortex().then((db)=> { 
    console.log("Cortex connected") 
    return db.createCollection(collname); 
}).catch((err)=> { 
    console.log("connection failed") 
}); 
} 

助けのためのThxを:)

+0

私は '約束ではありません)' connectWidthCortex(の戻り値を推測しています。確認できますか? – GPX

答えて

2

あなたはconnectWidthCortexの戻り値にthenを呼び出そうとしています。

connectWidthCortex機能return声明を持っていないので、undefinedを返します。

getSessionを呼び出すという約束を返す場合は、returnステートメントが必要です。

return xdevapi.getSession({ …

関連する問題