简体   繁体   English

如何使用Ionic Native Storage存储阵列数据?

[英]How to Store Array Data Using Ionic Native Storage?

I'm planning to use ionic native storage to store some translation history, whenever there's a word being translated. 我打算使用离子本机存储来存储一些翻译历史记录,只要有翻译的单词。 The translation action (date, translate word) will be store in the ionic native storage, and when I open history page, a list of translation history will be shown. 翻译操作(日期,翻译单词)将存储在离子本机存储中,当我打开历史页面时,将显示翻译历史列表。

Here's the most basic code I got from the ionic official website: 这是我从离子官方网站获得的最基本的代码:

export class HomePage {
  DataArray: Array<string> = [];

  constructor(public navCtrl: NavController, private storage: Storage) {

  }
  // set a key/value
  setData(){
  this.storage.set('age', 'Max');
  }
  // Or to get a key/value pair
  getData(){
  this.storage.get('age').then((val) => {
    console.log('Your age is', val);
  });
}
}

use getItem and SetItem 使用getItemSetItem

export class HomePage {
  DataArray: Array<string> = [];

  constructor(public navCtrl: NavController, private storage: NativeStorage) {

  }
  // set a key/value
  setData(){
  this.storage.setItem('keyOfData', JSON.stringify(DataArray));
  }
  // Or to get a key/value pair
  getData(){
  this.storage.getItem('keyOfData').then((val) => {
    console.log('Your age is', JSON.parse(val));
  });
}
}

the refrence Ionic native storage 参考离子本机存储

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

相关问题 Angular/Ionic Storage,如何动态存储数据 - Angular/Ionic Storage, how to store data dynamically 如何从ionic 4中的本机存储中删除数据 - How to remove data from native storage in ionic 4 Ionic 3 Cordova Native Storage存储修改后的数据 - Ionic 3 Cordova Native Storage storing modified data 使用IONIC Storage Service,如何获取和返回存储的JSON数据? - Using IONIC Storage Service, how to get and return stored JSON data? 如何在Angular4 / Ionic 3中的多维数组中存储和检索数据 - How to Store and Retrieve Data in Multidimensional Array in Angular4 / Ionic 3 如何将数据数组对象保存到离子SQlite存储(TypeScript,Angular 5,Ionic 3) - How to save a data array object to ionic SQlite storage (TypeScript, Angular 5, Ionic 3) 如何使用Ionic Storage使用Ionic 3从api存储json对象? - How to use Ionic Storage to store json object from api with ionic 3? 如何通过获取请求将mongodb的数据作为数组存储在本地存储中 - How to store data of mongodb through get request in local storage as an array 将来自 firebase 的数据存储到 firebase 离线存储与 ionic 5 - store data from firebase into firebase offline storage with ionic 5 如何使用会话存储在Angular 6上存储和检索数据? - How to store and retrieve data on Angular 6 using Session Storage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM