Search code examples
ionic4ionic-storage

How can I update a nested array with ionic4 storage


Using

openSavedForm() {
  this.storage.get('test').then((val) => {
    this.auditResults = JSON.parse(val);
    this.audit = this.auditResults
    this.auditOne = this.auditResults.siteVehicle; 
    console.log('pull all', this.audit);     
  });
}

I can view my key value pair stored items in sqlite. Here is a photo of the of the console.log

console.log of db

Is it possible to only update only the siteVehicle Array with

async saveFormUpdates() {
  this.newAudit =this.auditOne;
  await this.storage.set( 'test', JSON.stringify(this.newAudit));
  console.log ("storage", this.newAudit);
} 

with out deleting all the other arrays?


Solution

  • My async saveFormUpdates() was wrong. Turns out just saving this.audit instead of this.auditOne did everything with no further input from me.

    async saveFormUpdates() {
     this.newAudit = this.audit;
     await this.storage.set( 'test', JSON.stringify(this.newAudit));
     console.log ("storage", this.newAudit);
    }