我在Ionic应用程序中具有此功能:
clearTransactions() {
this.clearIndex = this.clearIndex + 1;
if (this.clearIndex < 3) {
console.log("click " + (3 - this.clearIndex) + " more times");
} else {
this.storage.clearItems()
this.storage.getItems().then(
items => {
this.items = items
console.log("test", this.items);
}
)
this.clearIndex = 0;
}
}
由于某种原因,this.storage.getItems()甚至在this.storage.clearItems()完成之前运行。谁能为这个问题提出解决方案?谢谢!
答案 0 :(得分:1)
clearItems 返回一个Promise,并且您已经完成了其余的代码,如下所示:
this.storage.clearItems().then(()=>{
// do things after clear
})