我目前正在开发一个使用Ionic 2的移动应用程序。 我有这组代码需要从SQLite检索数据,然后进一步将此值用于其他一些功能。见下文
this.credentials = _credentials;
let username = _credentials.username;
let password = _credentials.password;
let cVersion;
**this.localDbService.getcVersion().then((data) => {
cVersion = data;
});**
console.log(cVersion);
//build http header and make http call to servlet to retrieve details
let myHeaders: Headers = new Headers();
let digest = btoa(`${username}:${password}`);
cVersion 的值为 null,因为我猜测对 sqlite 的调用是异步的。我认为可行的一个快速修复方法是将所有下一个逻辑包含在数据库调用函数 getcVersion 中,但是是否有任何解决方案,例如等待数据库调用结束然后继续执行?
谢谢艾希礼
Replace this
this.credentials = _credentials;
let username = _credentials.username;
let password = _credentials.password;
let cVersion;
this.localDbService.getcVersion()
.then((data) => {
cVersion = data;
console.log(cVersion);
//build http header and make http call to servlet to retrieve details
let myHeaders: Headers = new Headers();
let digest = btoa(`${username}:${password}`);
});
干杯!