2

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

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

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

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

稍后我想查询具有特定电话号码的人:

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

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

4

2 回答 2

5

像这样的东西应该工作:

objectStore.createIndex("phoneNumberIndex", "phoneNumber", { multiEntry: true });
objectStore.index("phoneNumberIndex").get("4445554455").onsuccess = function(e) {
  console.log(JSON.stringify(e.target.result));
}
于 2012-06-15T22:33:56.290 回答
4

我认为您可以为此使用{multientry: true}createIndex 的参数。

于 2012-04-20T15:12:22.603 回答