Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

101
Visualizações
Getting multiple key values from Ionic2 storage

Using Ionic2 storage, I have done the following in a custom provider, I can confirm that the key-value pairs are set and I can retrieve them individually:

this.storage.set('one', 1);
this.storage.set('two', 2);
this.storage.set('three', 3);

The problem is I have a function in one of my pages that needs to access all three of these values for an HTTP request, so I can get one of them like this:

this.storage.get('one').then((value) => {
    // Preform http request sending value in POST data
});

But how do I get multiple key values all at once? Do I need to nest these calls, or is there a simpler way to access multiple keys in one call, so that I can do something like:

this.storage.get(['one', 'two', 'three']).then((values) => {
    console.log(values.one); // I dunno, something like this
});
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I used Promise.all for this purpose

Promise.all([this.storage.get("email"), this.storage.get("username")]).then(values => {

      console.log("email", values[0]);
      console.log("username", values[1]);

      // every other thing can happen here e.g call a method

});
about 4 years ago · Santiago Trujillo Relatório

0

You can simply do it as shown below.

this.storage.forEach( (value, key, index) => {
    console.log("value", value);//store these values as you wish
    console.log("key", key);
    console.log("Index" index);
})

From Api Doc.

 /**
   * Iterate through each key,value pair.
   * @param iteratorCallback a callback of the form (value, key, iterationNumber)
   * @return Promise that resolves when the iteration has finished.
   */

  forEach(iteratorCallback: (value: any, key: string, iterationNumber: Number) => any): Promise<null> {
    return this._dbPromise.then(db => db.iterate(iteratorCallback));
  }
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda