IndexedDB - 向嵌套对象添加键
我有一个具有以下结构的 IDB:
id: 1
name: "test"
operations: [
{
column: "active"
operator: "="
value: true
}
]
这里添加 ID,如下所示:
request.onupgradeneeded = e => {
let db = e.target.result
db.createObjectStore('filters', { autoIncrement : true, keyPath: 'id'})
}
用户可以添加一条新记录(在这种情况下它将具有 id:2 等),或者向现有记录添加操作。
我应该怎么做才能为每个操作添加自动递增键?
预期结果:
id: 1
name: "test"
operations: [
{
id: 1
column: "active"
operator: "="
value: true
},
{
id: 2
column: "age"
operator: ">"
value: 32
},
]
I have an IDB with the following structure :
id: 1
name: "test"
operations: [
{
column: "active"
operator: "="
value: true
}
]
Here the ID is added like so :
request.onupgradeneeded = e => {
let db = e.target.result
db.createObjectStore('filters', { autoIncrement : true, keyPath: 'id'})
}
Users can either add a new record, in which case it will have id: 2 and so on, or add an operation to an existing record.
What should I do to add an auto incrementing key to each operations ?
Expected result :
id: 1
name: "test"
operations: [
{
id: 1
column: "active"
operator: "="
value: true
},
{
id: 2
column: "age"
operator: ">"
value: 32
},
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IndexedDB 不会帮助您解决这个问题,您必须在应用程序代码中处理它。 IndexedDB中的自增键仅适用于对象的主键。
IndexedDB won't help you with that, you'll have to handle it in your application code. Auto incrementing keys in IndexedDB are only for the primary key of the object.