我认为答案是“你不能那样做”,但我想确定一下。假设我有一个对象:
var person = {
name: 'Joe',
phoneNumbers: [ '5555554455', '4445554455' ]
};
我想在 phoneNumbers 上创建一个索引:
objectStore.createIndex('phoneNumberIndex', 'phoneNumbers');
稍后我想查询具有特定电话号码的人:
index.get('4445554455').onsuccess = function(event) {
// Anything?
};
这会产生结果吗?如果没有,是否有其他方法可以做到这一点?
最佳答案
像这样的东西应该可以工作:
objectStore.createIndex("phoneNumberIndex", "phoneNumber", { multiEntry: true });
objectStore.index("phoneNumberIndex").get("4445554455").onsuccess = function(e) {
console.log(JSON.stringify(e.target.result));
}
关于javascript - IndexedDB:查询索引值 "contains",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8915648/