为了账号安全,请及时绑定邮箱和手机立即绑定

Ionic 等待功能完成后再运行第二个

Ionic 等待功能完成后再运行第二个

一只甜甜圈 2022-12-02 16:46:15
我的 Ionic App 中有这个功能: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() 完成之前运行。谁能为这个问题提出解决方案?谢谢!
查看完整描述

1 回答

?
偶然的你

TA贡献1841条经验 获得超3个赞

clearItems返回一个 promise,当它像这样完成时,您已经运行了剩余的代码:


   this.storage.clearItems().then(()=>{

      // do things after clear

    })


查看完整回答
反对 回复 2022-12-02
  • 1 回答
  • 0 关注
  • 81 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信