【发布时间】:2013-10-29 02:27:18
【问题描述】:
我是 IndexedDB 的新手。我想将这种数据放入索引数据库中:
var items = [{
title: 'A',
tags: ['h', 'f', 'g', 's', 't']
}, {
title: 'B',
tags: ['g', 'i', 'm']
}, {
title: 'C',
tags: ['f', 'l', 't', 'd']
}, {
title: 'D',
tags: ['i', 'u', 'v']
}, {
title: 'E',
tags: ['i', 'g']
}];
此外,另一个数组将作为我最喜欢的标签的来源:
var tagsArray = ['g', 'i']
(当然,这个数组可以包含任意数量的标签,而不仅仅是两个)。
我想从tagsArray 中提取包含每个标签的所有项目并得到这个数组:
var result = [{
title: 'B',
tags: ['g', 'i', 'm']
}, {
title: 'E',
tags: ['i', 'g']
}]
但即使在objectStore.createIndex('tags', 'tags', {multiEntry: true, unique: false}) 之后,我也不知道如何走得更远。我什至不明白 multiEntry 和 unique 参数的用途到底是什么。 indexedDB 是否允许仅在其键(数组)包含提供的每个关键字时才提取项目?
【问题讨论】:
标签: javascript arrays indexeddb