【问题标题】:How to remove data from native storage in ionic 4如何从 ionic 4 中的本机存储中删除数据
【发布时间】:2019-12-13 17:19:24
【问题描述】:

我实际上是在尝试删除本地存储中的精确数据,我尝试使用 splice,但我不确定它是否像这样工作,你有什么想法吗?

this.nativeStorage.getItem('AccepterPart').then(res => {
              for (let i of (JSON.parse(res))) {
                if (i['HISTO_N'] == this.currentNumInter) {
                  i['HISTO_Objet2'] = '106';
                  this.tabEffectuer.push(i);
                }
                var p = JSON.parse(res);
                var ind = p.findIndex(i => i['HISTO_N'] === this.currentNumInter);
                var inde = p.filter(i => i.HISTO_N !== this.currentNumInter);
                p.splice(inde);
                this.nativeStorage.setItem('AccepterPart', JSON.stringify(p));
              }
              this.nativeStorage.setItem('EffectuerPart', JSON.stringify(this.tabEffectuer));
            });  

【问题讨论】:

    标签: angular typescript cordova ionic4 cordova-nativestorage


    【解决方案1】:

    要彻底清除存储空间,请使用

    this.nativeStorage.clear();
    

    要删除字段,请使用

     this.nativeStorage.remove('AccepterPart');
    

    【讨论】:

    • 注意,我建议使用 Localstorage 而不是 Ionic Native 存储。由于 Localstorage 比 Ionic Nativestorage 更快。
    【解决方案2】:

    但是在数组 'AccepterPart' 中我想删除 var p ,我不能指出我想从 AccepterPart 中删除的数据?

    【讨论】:

      【解决方案3】:

      抱歉,回复时间太长了,但我注意到你所说的,但我使用了一些新的东西,但我不知道它不起作用。我尝试使用 findIndex 来了解我的值在键“AccepterPart”中的位置以及从我的键中删除该值的拼接,但我不知道为什么它不起作用,你知道吗?

      this.nativeStorage.getItem('AccepterPart').then(res => {
                    for (let i of (JSON.parse(res))) {
                      if (i['HISTO_N'] == this.currentNumInter) {
                        i['HISTO_Objet2'] = '106';
                        this.tabEffectuer.push(i);
                      }
                      var p = JSON.parse(res);
                      var ind = p.findIndex(i => i.HISTO_N == this.currentNumInter);
                      var inde = p.filter(i => i.HISTO_N != this.currentNumInter);
                      p.splice(ind);
                      this.nativeStorage.setItem('AccepterPart', JSON.stringify(p));
                    }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-04
        • 2020-12-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-02
        • 2023-03-25
        • 2019-05-16
        相关资源
        最近更新 更多