在IndexedDB中,如何为数据库中的所有记录从对象返回值?

时间:2019-11-22 07:54:46

标签: javascript indexeddb

我在IndexedDB objectStore中存储了几个对象。这些对象每个都有几个键,其中之一就是运动队的名称。我的对象示例:

enter image description here

我想做的是获取每个对象的full_name值。我可以通过使用objectStore.getAll()方法直接查询IndexedDB来做到这一点吗?我的代码当前如下所示:

async getData() {
  const db = await openDB('nbaPlayersTeams', 1);
  const tx = db.transaction('nbaPlayersTeamsStore', 'readonly');
  const store = tx.objectStore('nbaPlayersTeamsStore');
  const allTeams = await store.getAll();
  console.log(allTeams);
  db.close();
}

谢谢, 贝兹

0 个答案:

没有答案