angular – 从Ionic2存储中获取多个键值
发布时间:2020-12-17 17:59:10  所属栏目:安全  来源:网络整理 
            导读:使用Ionic2存储,我在自定义提供程序中完成了以下操作,我可以确认键值对已设置,我可以单独检索它们: this.storage.set('one',1);this.storage.set('two',2);this.storage.set('three',3); 问题是我的一个页面中有一个函数需要访问HTTP请求的所有这三个值,所
                
                
                
            | 
                         
 使用Ionic2存储,我在自定义提供程序中完成了以下操作,我可以确认键值对已设置,我可以单独检索它们: 
  
  
  
this.storage.set('one',1);
this.storage.set('two',2);
this.storage.set('three',3); 
 问题是我的一个页面中有一个函数需要访问HTTP请求的所有这三个值,所以我可以得到其中一个像这样: this.storage.get('one').then((value) => {
    // Preform http request sending value in POST data
}); 
 但是如何一次获得多个键值?我是否需要嵌套这些调用,或者是否有一种更简单的方法可以在一次调用中访问多个键,这样我就可以执行以下操作: this.storage.get(['one','two','three']).then((values) => {
    console.log(values.one); // I dunno,something like this
});
解决方法
 你可以简单地完成它,如下所示. 
  
  
  
        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,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));
  }
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
推荐文章
            站长推荐
            
        热点阅读
            