简体   繁体   English

如何使用 ionic4 存储更新嵌套数组

[英]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.我可以在 sqlite 中查看我的键值对存储项。 Here is a photo of the of the console.log这是 console.log 的照片

数据库的console.log

Is it possible to only update only the siteVehicle Array with是否可以只更新 siteVehicle 数组

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?不删除所有其他 arrays?

My async saveFormUpdates() was wrong.我的异步 saveFormUpdates() 是错误的。 Turns out just saving this.audit instead of this.auditOne did everything with no further input from me.结果只是保存 this.audit 而不是 this.auditOne 完成了所有操作,而我没有进一步的输入。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM