2015-05-11 85 views
2

我是IndexedDB中的新成员。我需要根据我的要求提取数据。 要求是: -从IndexedDB中检索数据

我有一个对象存储在IndexedDB中。

对象格式为: -

var _obj = { 
    COL_TITLE : '1', 
    COL_ID : 'proxyserver#1235', 
    COL_NAME : 'proxyserver', 
    COL_VERSION : ['TASK#1','TASK#2','TASK#3','TASK#4'] 
} 

我想根据'TASK#2'来获取数据。为了这个,我用这个

this.store.createIndex('VERSIONINDEX', 'data.COL_VERSION', {unique:false}); 

使用这个指数我正在读取记录创建索引'VERSIONINDEX'。但我有空阵列。 任何人都可以告诉我如何实现这一功能?

回答

1

具有多项索引。

// in onupgradeneeded 
store.createIndex('colVersionIndex','COL_VERSION', {multiEntry:true}); 

// in query 
store.index('colVersionIndex').openCursor('TASK#2').onsuccess = function() { 
    var cursor = this.result; 
    if(!cursor) return; 
    console.log('got task %o', cursor.value); 
};