我目前正在使用离子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中包含所有下一个逻辑,但有没有解决方案,比如等待数据库调用结束然后继续执行?
谢谢, 阿什利
答案 0 :(得分:2)
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}`);
});
干杯!