簡體   English   中英

IndexedDB:嘗試訪問表內的嵌套 object 時出現 SchemaError

[英]IndexedDB: SchemaError when trying to access nested object inside a table

我有一個名為 pos 的 IndexedDB,在該表中名為 pos_customers。 結構看起來像https://imgur.com/e9ZrxVm

現在我的目標是訪問計費 object 內的電話。 如果仔細觀察,那么帳單 object 是嵌套的。 所以,要訪問我寫了這段代碼:

if (search) {
database.table('pos_customers').where("first_name")
.startsWithIgnoreCase(search)
.or('email').startsWithIgnoreCase(search)
.or('billing.phone').startsWithIgnoreCase(search) //throws SchemaError
.toArray().then( (data) => {
    data.forEach(info => {
      for(let key in info) {
        console.log(`${key} ${info.email} ${info.billing.phone}`); //this will work obviously
        }
      }
)}
);

它向我顯示的警告:

Unhandled rejection: SchemaError: KeyPath billing.phone on object store pos_customers is not indexed.

是的,我是 Dexie 的新手,並且閱讀了許多 StackOverflow 答案,但無法獲得任何特定於 Dexie 嵌套對象的搜索。

先感謝您

我找到了一種方法來做到這一點:

首先,確保您嘗試訪問的字段已正確編入索引:(此處為 billing.phone)

const tables = {
  pos_customers: 'id,first_name,last_name,email,username,billing,billing.phone,shipping,avatar_url,is_true'
}

現在,確保通過將版本值增加 +1 來升級版本。

database.version(2).stores( applyFilters( DATABASE_ADD_TABLES_FILTER, tables ) ); //previous version(1)

現在,go 到 Chrome 上的應用程序:

  1. 打開Developer Tools (Ctrl+Shift+I / Cmd+Option+I)

  2. Go 到Applications Tab ,點擊你的目標數據庫,然后點擊Delete database

  3. 硬刷新頁面並嘗試您想要實現的任何目標。

它應該工作!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM