IndexedDB:值“包含”的查询索引

发布于 2024-12-27 12:00:01 字数 439 浏览 2 评论 0原文

我认为答案是“你不能那样做”,但我想确定一下。假设我有一个对象:

var person = {
    name: 'Joe',
    phoneNumbers: [ '5555554455', '4445554455' ]
};

我想在phoneNumbers上创建一个索引:

objectStore.createIndex('phoneNumberIndex', 'phoneNumbers');

稍后我想查询具有特定phoneNumber的人员:

index.get('4445554455').onsuccess = function(event) {
    // Anything?
};

这会产生结果吗?如果没有,还有其他方法可以做到这一点吗?

I think the answer is "you can't do it that way", but I wanted to be sure. Let's say I have an object:

var person = {
    name: 'Joe',
    phoneNumbers: [ '5555554455', '4445554455' ]
};

I want to create an index on phoneNumbers:

objectStore.createIndex('phoneNumberIndex', 'phoneNumbers');

Later I want to query for persons with a particular phoneNumber:

index.get('4445554455').onsuccess = function(event) {
    // Anything?
};

Will that produce a result? If not, is there another way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别念他 2025-01-03 12:00:01

像这样的东西应该有效:

objectStore.createIndex("phoneNumberIndex", "phoneNumber", { multiEntry: true });
objectStore.index("phoneNumberIndex").get("4445554455").onsuccess = function(e) {
  console.log(JSON.stringify(e.target.result));
}

Something like this should work:

objectStore.createIndex("phoneNumberIndex", "phoneNumber", { multiEntry: true });
objectStore.index("phoneNumberIndex").get("4445554455").onsuccess = function(e) {
  console.log(JSON.stringify(e.target.result));
}
不甘平庸 2025-01-03 12:00:01

我认为您可以使用 createIndex 的 {multientry: true} 参数来实现这一点。

I think you can use the {multientry: true} parameter of createIndex for that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文