【问题标题】:How to extract item if its key (array) contains each and every value from another array?如果项目的键(数组)包含另一个数组中的每个值,如何提取项目?
【发布时间】: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}) 之后,我也不知道如何走得更远。我什至不明白 multiEntryunique 参数的用途到底是什么。 indexedDB 是否允许仅在其键(数组)包含提供的每个关键字时才提取项目?

【问题讨论】:

    标签: javascript arrays indexeddb


    【解决方案1】:
    猜你喜欢
    • 2023-01-19
    • 2015-03-10
    • 2014-09-24
    • 1970-01-01
    • 1970-01-01
    • 2020-04-23
    • 2021-12-26
    • 2019-02-04
    • 2020-05-15
    相关资源
    最近更新 更多