2017-02-28 43 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

您正在试图调用then上的connectWidthCortex返回值。

connectWidthCortex功能没有return声明,所以它返回undefined

如果您想返回致电getSession给您的承诺,那么您需要一个return声明。

return xdevapi.getSession({ …

相关问题