【问题标题】:How to return and store a document in a value with pouchdb?如何使用 pouchdb 将文档返回并存储在一个值中?
【发布时间】:2019-10-02 11:34:26
【问题描述】:

我将 ionic 4 与 pouchdb 一起使用。 我想从文档中获取价值。

我希望从 pouchdb 文档中获取 id_observateur 值。 我尝试使用箭头功能,但它不起作用

let get_observateur = () => {
     PouchDB.plugin(PouchDBFind);
     PouchDB.plugin(require('pouchdb-adapter-cordova-sqlite'));
     this.observateurlocal= new PouchDB('observateurlocal', {adapter: 
      'cordova-sqlite'});

       this.observateurlocal.get('observateurlocal').then((doc) =>{
            return doc.id_observateur;

             });
            }; 
         // Call the function 
         console.log(get_observateur);

【问题讨论】:

    标签: javascript angular typescript pouchdb


    【解决方案1】:

    这应该可行:

    let get_observateur = async () => {
      PouchDB.plugin(PouchDBFind);
      PouchDB.plugin(require('pouchdb-adapter-cordova-sqlite'));
      this.observateurlocal = new PouchDB('observateurlocal', {
        adapter: 'cordova-sqlite'
      });
     return await this.observateurlocal.get('observateurlocal');
    };
    
    console.log(await get_observateur);
    

    【讨论】:

    • 它给出了这个错误:错误 TS1308: 'await' 表达式只允许在异步函数中
    • 我这样做了:this.observateur = this.observateurlocal.get('observateurlocal').then( res => res.id_observateur); console.log(this.observateur);但我有一个数组中的结果作为 ZoneAwarePromise 对象!这似乎是一个承诺
    猜你喜欢
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多