首页 > 解决方案 > 在 IndexedDB 中调用 add 或 put 时如何找出导致 ConstraintError 的索引?

问题描述

每当使用创建索引时,调用 add 或 put 时都可以返回unique=truea 。ConstraintError

可以从中读取的错误IDBReaquest.errorDOMException没有足够信息的错误。以下是 Chrome 返回的内容:

{name:'ConstraintError', message: 'Unable to add key to index 'country-city': at least one key does not satisfy the uniqueness requirements.'}

,和火狐:

{name:'ConstraintError', message: 'A mutation operation in the transaction failed because a constraint was not satisfied.'}

很明显,浏览器知道导致错误的索引。

但是有没有人知道有什么方法可以找到它?

标签: indexeddb

解决方案


推荐阅读