【发布时间】:2022-01-06 06:26:27
【问题描述】:
我有一个名为 pos 的 IndexedDB,在该表中名为 pos_customers。结构看起来像https://imgur.com/e9ZrxVm
现在我的目标是访问计费对象内的电话。如果您仔细观察,那么 billing 对象是嵌套的。所以,要访问我写了这段代码:
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上指定索引的位置 -
@Josh 这里是:imgur.com/a/hkJXbqY 如果您需要其他任何东西,请告诉我。
-
现在我尝试添加
database.version(2).stores(table2);const table2 = { pos_customers : 'id,first_name,last_name,email,username,billing,billing.phone,shipping,avatar_url,is_true', }控制台显示:Unhandled rejection: Error: Failed to execute 'index' on 'IDBObjectStore': The specified index was not found.
标签: javascript indexeddb dexie