如何使用NgxIndexedDB从indexedDB索引获取多个记录?

时间:2019-02-22 15:50:38

标签: javascript indexeddb

我已经使用NgxIndexedDB创建了IndexedDB数据库,并创建了一个唯一的索引。当我使用var = fields.Boolean(string='', default=True) 读取记录时,尽管我知道还有更多记录匹配,但仅返回一条记录。获取所有匹配记录的机制是什么?

getByIndex()

1 个答案:

答案 0 :(得分:0)

经过几次尝试和错误,我能够按照Josh的提示使用getAll函数来做到这一点。谢谢乔希。就是这样。

  this.db.openDatabase(1, evt => {
      let objectStore = evt.currentTarget.result.createObjectStore(‘empCollection’, { keyPath: '_id', autoIncrement: false });
      console.log("Open DB is called...")
      objectStore.createIndex(‘empname’, ‘empname’, { unique: false });
    });


    let index_detail:IndexDetails = {
      indexName: 'empname',
      order: 'asc'
    }


 this.db.getAll(‘empCollection’,IDBKeyRange.only(“Dave”),index_details).then(
          names => {
            console.log(names);
          },
          error => {
            console.log(error);
          }
        );